首页 > 解决方案 > 在 read.excel() 上弹出回溯消息并接收类型错误

问题描述

我的项目是使用python进行分析。我有一些关于 excel 的数据,但我只需要使用一些数据而不是所有数据(即特定日期,例如仅从 1 月到 2 月)。我的问题是

  1. 如何仅选择所需的数据(如特定日期)并插入到 python 代码中?
  2. 当我尝试运行文件 (PMEB_Para.py) 时出现此错误,我可以知道该错误是什么意思吗?这是我收到的错误
     C:\Users\user\Desktop\CIV4210\Research\Package for FYP\data and code>python PMEB_Main.py
Traceback (most recent call last):
  File "PMEB_Main.py", line 483, in <module>
    Tb, Station, Rough, Veg, Sp = readdata(Para.period)
  File "C:\Users\user\Desktop\CIV4210\Research\Package for FYP\data and code\PMEB_Para.py", line 397, in readdata
    rough = pd.read_excel('roughness.xlsx', parse_dates=['Dt'], dtype=Dtype, dayfirst=True)
  File "C:\Users\user\AppData\Roaming\Python\Python36\site-packages\pandas\util\_decorators.py", line 296, in wrapper
    return func(*args, **kwargs)
TypeError: read_excel() got an unexpected keyword argument 'dayfirst'

PMEB_Para.py 文件中第 390-397 行的代码

def readdata(period):
station = readstation(period)
tb = pd.read_csv('TB.csv', dtype=Dtype, parse_dates=['Dt'], dayfirst=True)
tb = tb.loc[(tb['Dt'] > period[0]) & (tb['Dt'] < period[1])]
tb['Date'] = [x.date() for x in tb['Dt']]
tb['Time'] = [x.time() for x in tb['Dt']]
tb = tb.sort_values(['Date', 'Quad', 'BI', 'Pol'])
rough = pd.read_excel('roughness.xlsx', parse_dates=['Dt'], dtype=Dtype, dayfirst=True)

提前感谢您的时间!

标签: python

解决方案


推荐阅读