17

I can't load the xlsx file

import pandas
y=pandas.read_excel("as.xlsx",sheetname=0)
y

This is the error message

TypeError                                 Traceback (most recent call last)
<ipython-input-5-54208838b8e5> in <module>
      1 import pandas
----> 2 y=pandas.read_excel("as.xlsx",sheetname=0)
      3 y

c:\users\lenovo-pc\appdata\local\programs\python\python37\lib\site-packages\pandas\util\_decorators.py in wrapper(*args, **kwargs)
    206                 else:
    207                     kwargs[new_arg_name] = new_arg_value
--> 208             return func(*args, **kwargs)
    209 
    210         return wrapper

c:\users\lenovo-pc\appdata\local\programs\python\python37\lib\site-packages\pandas\io\excel\_base.py in read_excel(io, sheet_name, header, names, index_col, usecols, squeeze, dtype, engine, converters, true_values, false_values, skiprows, nrows, na_values, keep_default_na, verbose, parse_dates, date_parser, thousands, comment, skip_footer, skipfooter, convert_float, mangle_dupe_cols, **kwds)
    304         if arg in kwds:
    305             raise TypeError(
--> 306                 "read_excel() got an unexpected keyword argument " "`{}`".format(arg)
    307             )
    308 

TypeError: read_excel() got an unexpected keyword argument `sheetname`
3
  • 9
    The correct argument is sheet_name - note the underscore. I'm voting to close as a typo. Commented Aug 4, 2019 at 16:40
  • 5
    @DavidW. This is not a typo, but arises from running old code. The parameter sheetname was depreciated and then replaced with sheet_name in 2018. See Github issue #20920 Commented Jul 8, 2020 at 7:34
  • @mjfwest I didn't know that - that's a useful detail Commented Jul 8, 2020 at 7:40

4 Answers 4

31

You have a syntax error

Try

y=pandas.read_excel("as.xlsx",sheet_name=0)
Sign up to request clarification or add additional context in comments.

Comments

4

It seems that this "sheet_name" could be language dependent. The argument is also positional, so you can just drop "sheet_name" and write:

y=pandas.read_excel("as.xlsx",0)

I have tried version Pandas 1.0.5 and xlrd 1.2.0

Comments

0

Syntax error. Should be:

sheet_name = 'xxx'

1 Comment

how is this different than the other answers already posted?
-1

install xlrd from command prompt using below:

  1. conda install xlrd
  2. pip install xlrd

It is referred to as Sheetname

1 Comment

OP's problem was caused just by a simple typo, I don't think this answer is helpful here. You might want to clarify why you think this is helpful by editing it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.