Python Forum
pandas.read_excel does not seem to work
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pandas.read_excel does not seem to work
#1
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??
Reply
#2
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
Reply
#3
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
Reply
#4
(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
hobbyist and nilamo like this post
Reply
#5
@snippsat: You are amazing!! Finally it works!!! Thanks...
nilamo likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  For Loop Works Fine But Append For Pandas Doesn't Work knight2000 2 1,930 Dec-18-2021, 02:38 AM
Last Post: knight2000
  Cannot make 'pandas' module to work... ellie145 2 4,136 Jan-05-2021, 09:38 PM
Last Post: ellie145

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020