Dataframe 无法使用熊猫数据框提取列名

Dataframe 无法使用熊猫数据框提取列名,dataframe,Dataframe,没有将文件读入两列,因为您有一个空格作为分隔符,默认值为逗号。指定空间: KeyError: 'Name' >>> df=pd.read_csv(text_file) >>> print(df) Name Age 0 Ritesh 32 1 Priyanka 29 >>> print(df['Name'].where(df['Name'] == 'Ritesh')) Traceback (most recent ca

没有将文件读入两列,因为您有一个空格作为分隔符,默认值为逗号。指定空间:

KeyError: 'Name'
>>> df=pd.read_csv(text_file)
>>> print(df)
       Name Age
0     Ritesh 32
1  Priyanka 29 
>>> print(df['Name'].where(df['Name'] == 'Ritesh'))
Traceback (most recent call last):
  File "/Users/reyansh/venv/lib/python3.8/site-packages/pandas/core/indexes/base.py", line 2646, in get_loc
    return self._engine.get_loc(key)
  File "pandas/_libs/index.pyx", line 111, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/index.pyx", line 138, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/hashtable_class_helper.pxi", line 1619, in pandas._libs.hashtable.PyObjectHashTable.get_item
  File "pandas/_libs/hashtable_class_helper.pxi", line 1627, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'Name'

During handling of the above exception, another exception occurred:

请改进问题的格式。你问题的第二部分似乎不见了。此外,您试图解决什么问题?我已经修复了您的代码块,但请阅读。你不能把你的代码扔到这里,然后指望我们用它做点什么。你需要问一个明确的问题。
df = pd.read_csv(text_file, " ")