Skip to content

Commit 4aa25c2

Browse files
committed
BUG: read_excel return empty dataframe when using usecols
- [x] closes #18273 - [x] tests added / passed - [x] passes git diff master --name-only -- "*.py" | grep "pandas/" | xargs -r flake8 - [x] whatsnew entry As mentioned read_excel returns an empty DataFrame when usecols argument is a list of strings. Now lists of strings are correctly interpreted by read_excel function.
1 parent 0c9192d commit 4aa25c2

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pandas/io/excel.py

+7
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,15 @@ def _excel2num(x):
477477

478478
if isinstance(usecols, int):
479479
return i <= usecols
480+
# check if usecols is a string that indicates a comma separated list of
481+
# Excel column letters and column ranges
480482
elif isinstance(usecols, compat.string_types):
481483
return i in _range2cols(usecols)
484+
# check if usecols is a list of strings, each one indicating a Excel
485+
# column letter or a column range
486+
elif all(isinstance(x, compat.string_types) for x in usecols):
487+
usecols_str = ",".join(usecols)
488+
return i in _range2cols(usecols_str)
482489
else:
483490
return i in usecols
484491

0 commit comments

Comments
 (0)