Python Forum

Full Version: pandas.read_excel does not seem to work
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I run this code:

dataframe = pandas.read_csv(filename, usecols=[2], engine = 'python', skipfooter = skipfooter) 
and runs perfectly.But when I run this command:

dataframe = pandas.read_excel(filename, usecols=[2], engine = 'python', skipfooter = skipfooter)


I get this:

Error:
ValueError: Unknown engine:python
When I omit engine and skipfooter (as I saw by googling related answers) the program "stucks" for hours... Obviously I use .csv file in the first one and .xlsx in the second one. Any idea what I miss here??
pandas.read_excel there is no engine called python,only for read_csv.
Usually don't specify engine use default,try without usecols=[2].
Pandas read_excel() Example

So if i would read Excel Sample Data.
import pandas

df = pandas.read_excel('SampleData.xlsx', sheet_name='SalesOrders')
print(df.head())
Output:
OrderDate Region Rep Item Units Unit Cost Total 0 2019-01-06 East Jones Pencil 95 1.99 189.05 1 2019-01-23 Central Kivell Binder 50 19.99 999.50 2 2019-02-09 Central Jardine Pencil 36 4.99 179.64 3 2019-02-26 Central Gill Pen 27 19.99 539.73 4 2019-03-15 West Sorvino Pencil 56 2.99 167.44
If work try usecols=[2]
import pandas

df = pandas.read_excel('SampleData.xlsx', usecols=[2], sheet_name='SalesOrders')
print(df.head())
Output:
Rep 0 Jones 1 Kivell 2 Jardine 3 Gill 4 Sorvino
I cannot use 'SampleData.xlsx' because the excel is loaded from an open file button, so I don't know the path a priori. However I get this error:

Error:
raise XLRDError(FILE_FORMAT_DESCRIPTIONS[file_format]+'; not supported') xlrd.biffh.XLRDError: Excel xlsx file; not supported
(Feb-01-2021, 01:54 PM)hobbyist Wrote: [ -> ]xlrd.biffh.XLRDError: Excel xlsx file; not supported
Make sure your Pandas is up to data and install openpyxl(what pandas now use as default to open Excel files if installed)
pandas Wrote:xlrd has explicitly removed support for anything other than xls files.
So in newer versions xlrd is not used at all unless try to open old xls files
pip install pandas --upgrade
pip install openpyxl --upgrade
Then try again,this i have tested in virtual environment so it do works.
import pandas

df = pandas.read_excel('SampleData.xlsx', sheet_name='SalesOrders')
print(f'Your pandas version is: {pandas.__version__}')
print('-' * 30)
print(df.head())
Output:
Your pandas version is: 1.2.1 ------------------------------ OrderDate Region Rep Item Units Unit Cost Total 0 2019-01-06 East Jones Pencil 95 1.99 189.05 1 2019-01-23 Central Kivell Binder 50 19.99 999.50 2 2019-02-09 Central Jardine Pencil 36 4.99 179.64 3 2019-02-26 Central Gill Pen 27 19.99 539.73 4 2019-03-15 West Sorvino Pencil 56 2.99 167.44
@snippsat: You are amazing!! Finally it works!!! Thanks...