我的要求是我有两个CSV文件,我需要在两个文件的最后一列进行比较和执行操作。我使用熊猫打开两个CSV文件,当我打开第二个CSV文件并尝试访问任何列 时会返回错误。无法在同一个python程序中打开多个csv文件
import pandas as pd1
import pandas as pd
# comma delimited is the default
df = pd.read_csv("results.csv", header = 0)
spamColumnValues=df['isSpam'].values
df1=pd1.read_csv("compare.csv",header=0)
spamCompareValues=df1['isSpam'].values
得到一个错误
File "/Library/Python/2.7/site-packages/pandas/core/frame.py", line 1964, in __getitem__
return self._getitem_column(key)
File "/Library/Python/2.7/site-packages/pandas/core/frame.py", line 1971, in _getitem_column
return self._get_item_cache(key)
File "/Library/Python/2.7/site-packages/pandas/core/generic.py", line 1645, in _get_item_cache
values = self._data.get(item)
File "/Library/Python/2.7/site-packages/pandas/core/internals.py", line 3590, in get
loc = self.items.get_loc(item)
File "/Library/Python/2.7/site-packages/pandas/core/indexes/base.py", line 2444, in get_loc
return self._engine.get_loc(self._maybe_cast_indexer(key))
File "pandas/_libs/index.pyx", line 132, in pandas._libs.index.IndexEngine.get_loc (pandas/_libs/index.c:5280)
File "pandas/_libs/index.pyx", line 154, in pandas._libs.index.IndexEngine.get_loc (pandas/_libs/index.c:5126)
File "pandas/_libs/hashtable_class_helper.pxi", line 1210, in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas/_libs/hashtable.c:20523)
File "pandas/_libs/hashtable_class_helper.pxi", line 1218, in pandas._libs.hashtable.PyObjectHashTable.get_item (pandas/_libs/hashtable.c:20477)
KeyError: 'isSpam'
任何人都可以指出我的错误,或者是不可能的大熊猫做到这一点?
无论是CSV文件,可以在
https://drive.google.com/file/d/0B3XlF206d5UrUENtZlcwd0pVLW8/view?usp=sharing
https://drive.google.com/file/d/0B3XlF206d5UrbGdJRFM5TURmejQ/view?usp=sharing
与列添加的第一列姓名到.csv的 – jacoblaw
为什么你用不同的别名导入'熊猫'两次? –