read_excel return empty dataframe when using usecols
See original GitHub issueIn [3]: data = pd.read_excel("A.xlsx")
In [4]: data
Out[4]:
A B
0 1 2
1 3 4
In [5]: data1 = pd.read_excel("A.xlsx",usecols=['B'])
In [6]: data1
Out[6]:
Empty DataFrame
Columns: []
Index: []
In [7]: pd.__version__
Out[7]: '0.21.0'
Problem description
Having a excel file name A.xlsx(or A.xls) with column A,B read_excel return empty dataframe if usecols used
Issue Analytics
- State:
- Created 6 years ago
- Reactions:12
- Comments:32 (11 by maintainers)
Top Results From Across the Web
python - pandas,read_excel, usecols with list input generating ...
A possible approach is to read few rows and find the location of the column and then read the file second time. import...
Read more >pandas read_excel usecols empty dataframe
To read an excel file as a DataFrame, use the pandas read_excel() method. ... entry As mentioned read_excel returns an empty DataFrame when...
Read more >Pandas read_excel() - Reading Excel File in Python
We can use the pandas module read_excel() function to read the excel file data into a DataFrame object. If you look at an...
Read more >Pandas Read Excel with Examples
Use pandas.read_excel() function to read excel sheet into pandas DataFrame, by default it loads the first sheet from the excel file and parses...
Read more >pandas.read_excel — pandas 1.5.2 documentation
Read an Excel file into a pandas DataFrame. ... If a subset of data is selected with usecols , index_col is based on...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For me Instead of typing
usecols=['B']
, tryusecols='B'
Copying my comment from #20480, welcome any feedback on how this api should work
#18273 is actually two somewhat separate problems and we have a bit of an API tangle here
'foo'
in the spreadsheet) tousecols
doesn’t work anymoreNumber 2 wasn’t part of the
read_excel
documented args, but once worked, because this param used to be calledparse_cols
(#17774), and if you passed something tousecols
it would get passed down to the TextParser logic and do the right thing https://github.com/pandas-dev/pandas/blob/1915ffc53ea60494f24d83844bbff00efa392c82/pandas/io/excel.py#L529Not sure what the solution is, there could be ambiguous cases (column titled
'A'
in spreadsheet columnB
), that would be easiest to handle with separate kwargs. Or could just have usecols do everything and warn in cases of ambiguity.