Skip to content

Commit

Permalink
BUG: read_excel return empty dataframe when using usecols
Browse files Browse the repository at this point in the history
- [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.
  • Loading branch information
jacksonjos committed Mar 25, 2018
1 parent 0c9192d commit 4aa25c2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pandas/io/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,15 @@ def _excel2num(x):

if isinstance(usecols, int):
return i <= usecols
# check if usecols is a string that indicates a comma separated list of
# Excel column letters and column ranges
elif isinstance(usecols, compat.string_types):
return i in _range2cols(usecols)
# check if usecols is a list of strings, each one indicating a Excel
# column letter or a column range
elif all(isinstance(x, compat.string_types) for x in usecols):
usecols_str = ",".join(usecols)
return i in _range2cols(usecols_str)
else:
return i in usecols

Expand Down

0 comments on commit 4aa25c2

Please sign in to comment.