我刚刚开始使用 pandas 库。尽管我进行了研究,但我仍然没有弄清楚。我想提取名为 q 的列的数据。但它给出了一个错误。我怎样才能做到这一点?
import pandas as pd
data = pd.read_excel('test1.xlsx')
df = pd.DataFrame(data)
print(df.loc[df['q']])
错误:
Traceback (most recent call last):
File "c:/Users/sabca/visual studio code projects/webscraping/pandastest.py", line 11,
in <module>
print(df.loc[df['q']])
File "C:\Users\sabca\AppData\Local\Programs\Python\Python38\lib\site-
packages\pandas\core\indexing.py", line 879, in __getitem__
return self._getitem_axis(maybe_callable, axis=axis)
File "C:\Users\sabca\AppData\Local\Programs\Python\Python38\lib\site-
packages\pandas\core\indexing.py", line 1099, in _getitem_axis
return self._getitem_iterable(key, axis=axis)
File "C:\Users\sabca\AppData\Local\Programs\Python\Python38\lib\site-
packages\pandas\core\indexing.py", line 1037, in _getitem_iterable
keyarr, indexer = self._get_listlike_indexer(key, axis, raise_missing=False)
File "C:\Users\sabca\AppData\Local\Programs\Python\Python38\lib\site-
packages\pandas\core\indexing.py", line 1254, in _get_listlike_indexer
self._validate_read_indexer(keyarr, indexer, axis, raise_missing=raise_missing)
File "C:\Users\sabca\AppData\Local\Programs\Python\Python38\lib\site-
packages\pandas\core\indexing.py", line 1298, in _validate_read_indexer
raise KeyError(f"None of [{key}] are in the [{axis_name}]")
KeyError: "None of [Index(['qwe1', 'asdf1', 'adfs4', 'wer7', 'tyu1', 'ghfhg5'],
dtype='object')] are in the [index]"
呼啦一阵风
牛魔王的故事
慕桂英546537
aluckdog
相关分类