keyerror:从xlsx导入后的“日期”

时间:2020-05-21 18:37:31

标签: python python-3.x pandas datetime xlsx

我正在尝试在jupyter中导入这个简短的xlsx

enter image description here

使用此代码

import pandas as pd
fields=['Date', 'A', 'C']
df = pd.read_excel('/home/maspis/Scrivania/date_try.xlsx', sheet_name='I1', usecols=fields)
#df['Date']= pd.to_datetime(df['Date'])
df.info()

我得到以下输出:

<class 'pandas.core.frame.DataFrame'>
Index: 0 entries
Empty DataFrame'

然后,当我使用pd.to_datetime时,得到以下内容

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   3077             try:
-> 3078                 return self._engine.get_loc(key)
   3079             except KeyError:
......

KeyError: 'Date'

您能帮我解决这个问题吗?

谢谢, G

0 个答案:

没有答案