【问题标题】:TypeError with pandas.read_excel带有 pandas.read_excel 的 TypeError
【发布时间】:2023-04-05 00:20:01
【问题描述】:

我无法加载 xlsx 文件

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

这是错误信息

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`

【问题讨论】:

  • 正确的参数是sheet_name - 注意下划线。我投票结束是一个错字。
  • @DavidW。这不是错字,而是由运行旧代码引起的。参数sheetname在2018年被贬值,然后被sheet_name替换。见Github issue #20920
  • @mjfwest 我不知道 - 这是一个有用的细节

标签: python pandas


【解决方案1】:

你有一个语法错误

试试

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

【讨论】:

    【解决方案2】:

    似乎这个“sheet_name”可能与语言有关。该参数也是位置参数,因此您可以删除“sheet_name”并编写:

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

    我已经尝试过 Pandas 1.0.5 和 xlrd 1.2.0 版本

    【讨论】:

      【解决方案3】:

      使用以下命令从命令提示符安装xlrd

      1. conda install xlrd
      2. pip install xlrd

      简称Sheetname

      【讨论】:

      • OP 的问题是由一个简单的错字引起的,我认为这个答案在这里没有帮助。您可能想通过编辑来阐明为什么您认为这很有帮助。
      猜你喜欢
      • 2016-02-11
      • 2021-06-09
      • 1970-01-01
      • 2015-10-12
      • 2020-11-11
      • 2014-05-08
      • 2018-02-18
      • 2016-08-23
      • 2016-06-22
      相关资源
      最近更新 更多