import pandas as pd
c=str(input())
d=int(input())
path='counties.csv'
df=pd.read_csv(path)
df.loc[:,'date']=df['date'].str.replace('/','').astype('int32')
print(df.head())
print(df.loc[(df['county']==c)&(df['data']=='2020124'),:])
为什么会出现
date county state cases deaths
0 2020121 Snohomish Washington 1 0
1 2020122 Snohomish Washington 1 0
2 2020123 Snohomish Washington 1 0
3 2020124 Cook Illinois 1 0
4 2020124 Snohomish Washington 1 0
Traceback (most recent call last):
File "D:\pycharm python\venv\lib\site-packages\pandas\core\indexes\base.py", line 3080, in get_loc
return self._engine.get_loc(casted_key)
File "pandas_libs\index.pyx", line 70, in pandas._libs.index.IndexEngine.get_loc
File "pandas_libs\index.pyx", line 101, in pandas._libs.index.IndexEngine.get_loc
File "pandas_libs\hashtable_class_helper.pxi", line 4554, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas_libs\hashtable_class_helper.pxi", line 4562, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'data'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\pycharm python\小学期\ibc.py", line 8, in
print(df.loc[(df['county']==c)&(df['data']=='2020124'),:])
File "D:\pycharm python\venv\lib\site-packages\pandas\core\frame.py", line 3024, in getitem
indexer = self.columns.get_loc(key)
File "D:\pycharm python\venv\lib\site-packages\pandas\core\indexes\base.py", line 3082, in get_loc
raise KeyError(key) from err
KeyError: 'data'