I'm trying to import data into pandas from an Excel file, but I'm getting an error when typing out the following:
energy = pd.read_excel('Indicators.xls',
'Energy',
skiprows=17,
skip_footer=38,
usecols=['C','D','E','F'])
But I'm getting an error stating that 'C'
is not in list. When evaluating the Excel file in Excel, it clearly has a C
column. The pandas documentation says the following:
usecols : int or list, default None
If None then parse all columns, If int then indicates last column to be parsed. If list of ints then indicates list of column numbers to be parsed. If string then indicates comma separated list of Excel column letters and column ranges (e.g. “A:E” or “A,C,E:F”). Ranges are inclusive of both sides.
So I'd like to import just C
to F
, so I've tried both suggestions as mentioned above.
I get the following error:
ValueError: 'C' is not in list
Not sure why this won't work. Any suggestions?
Have a look at version you're using. If this version is older than version 0.21.0 then try to use parse_cols instead.
columns = 'A:L'
df = pd.read_excel(file_to_process, sheetname=sheetname, parse_cols=columns)
I had the same issue with usecols. After changing to parse_cols it works properly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With