小白用PANDAS 经常报错,就大大帮忙解决
基本代码都是按照教材打上去或者复制上去的,不知道为什么莫名其妙报错import pandas as pd
pd.set_option('expand_frame_repr', False) # 当列太多时显示完整
# =====导入数据
df = pd.read_csv(
r'D:\python\xbx_stock_2019\data\a_stock_201903.csv',
encoding='gbk',
skiprows=1
)
print(df.groupby('交易日期'))
然后报错是这样的
C:\Users\PC\anaconda3\python.exe D:/python/123/111.py
Traceback (most recent call last):
File "D:/python/123/111.py", line 12, in <module>
print(df.groupby('交易日期'))
File "C:\Users\PC\anaconda3\lib\site-packages\pandas\core\frame.py", line 6717, in groupby
return DataFrameGroupBy(
File "C:\Users\PC\anaconda3\lib\site-packages\pandas\core\groupby\groupby.py", line 560, in __init__
grouper, exclusions, obj = get_grouper(
File "C:\Users\PC\anaconda3\lib\site-packages\pandas\core\groupby\grouper.py", line 811, in get_grouper
raise KeyError(gpr)
KeyError: '交易日期'
Process finished with exit code 1