companyName = companyList[companyID-1]
data = pd.read_csv("C:\Feedback and Complaints_Sample Dataset.csv",sep=',') # read file with panda module
desiredOutput = data["Co. Name" == companyName]
desiredOutput.to_csv("1.txt", sep = ",", index=False, header=False)
desiredOutput = data["Co. Name" == companyName] # For desiredOutput, it'll be when co-name equals companyName
我在使用panda模块时收到一条错误消息。 请告知。 以下是错误消息:
desiredOutput = data["Co. Name" == companyName]
File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 1797, in __getitem__
return self._getitem_column(key)
File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 1804, in _getitem_column
return self._get_item_cache(key)
File "C:\Python27\lib\site-packages\pandas\core\generic.py", line 1084, in _get_item_cache
values = self._data.get(item)
File "C:\Python27\lib\site-packages\pandas\core\internals.py", line 2851, in get
loc = self.items.get_loc(item)
File "C:\Python27\lib\site-packages\pandas\core\index.py", line 1572, in get_loc
return self._engine.get_loc(_values_from_object(key))
File "pandas\index.pyx", line 134, in pandas.index.IndexEngine.get_loc (pandas\index.c:3824)
File "pandas\index.pyx", line 154, in pandas.index.IndexEngine.get_loc (pandas\index.c:3704)
File "pandas\hashtable.pyx", line 686, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:12280)
File "pandas\hashtable.pyx", line 694, in pandas.hashtable.PyObjectHashTable.get_item (pandas\hashtable.c:12231)
KeyError: False
如果有
data
DataFrame with column,其名称为"Co. Name"
,则可以使用以下代码片段获取具有指定条件的所有行:相关问题 更多 >
编程相关推荐