python pandas dataframe index, error TypeError: Input must be iterable, pandas version perhaps wrong
python pandas dataframe index, error TypeError: Input must be iterable, pandas version perhaps wrong
我正在使用麻省理工学院的 eda-explorer python 库,它允许从特定的可穿戴生物传感器导入生理数据文件。该库使用 pandas DataFrames 来存储生理时间序列。我一直在不同的计算设置中使用这个库。当我尝试在我的 ubuntu 15.10 环境中使用它时,我收到一条我不理解的错误消息。它与以下函数相关,该函数有助于将数据放入 DataFrame 并进行一些初始转换:
def loadData_E4(filepath):
# Load data
data = pd.DataFrame.from_csv(os.path.join(filepath,'EDA.csv'))
data.reset_index(inplace=True)
# Get the startTime and sample rate
startTime = pd.to_datetime(float(data.columns.values[0]),unit="s")
sampleRate = float(data.iloc[0][0])
data = data[data.index!=0]
data.index = data.index-1
这会导致以下错误消息:
In [1]:
run batch_edaexplorer_template.py
Classifying data for ...[my file location]...
---------------------------------------------------------------------
TypeError Traceback (most recent call last)
/...mypath/eda-explorer-master/batch_edaexplorer_template.py in <module>()
69 elif dataType=='e4':
70 print "Classifying data for " + filepath
---> 71 labels,data = classify(filepath,classifierList,pickleDirectory,lf.loadData_E4)
72 elif dataType=="misc":
73 print "Classifying data for " + filepath
/...mypath/eda-explorer-master/EDA_Artifact_Detection_Script.pyc in classify(filepath, classifierList, pickleDirectory, loadDataFunction)
225
226 # Load data
--> 227 data = loadDataFunction(filepath)
228
229 # Get pickle List and featureNames list
/...mypath/eda-explorer-master/load_files.pyc in loadData_E4(filepath)
58 sampleRate = float(data.iloc[0][0])
59 data = data[data.index!=0]
---> 60 data.index = data.index-1
61
62 # Reset the data frame assuming 4Hz samplingRate
/usr/lib/python2.7/dist-packages/pandas/core/index.pyc in __sub__(self, other)
1161 warnings.warn("using '-' to provide set differences with Indexes is deprecated, "
1162 "use .difference()",FutureWarning)
-> 1163 return self.difference(other)
1164
1165 def __and__(self, other):
/usr/lib/python2.7/dist-packages/pandas/core/index.pyc in difference(self, other)
1314
1315 if not hasattr(other, '__iter__'):
-> 1316 raise TypeError('Input must be iterable!')
1317
1318 if self.equals(other):
TypeError: Input must be iterable!
我的 windows PC 上没有收到此错误消息。我在 ubuntu 环境中使用 pandas 版本 0.15.0。这可能是与索引相关的特定语法只允许在 pandas 的更高版本中使用的问题吗?我应该如何更正语法以使其适用于旧版本的 pandas?还是我没抓住要点?
尝试 data.index = pd.Index(data.index.values-1)
而不是 data.index = data.index-1
。
我正在使用麻省理工学院的 eda-explorer python 库,它允许从特定的可穿戴生物传感器导入生理数据文件。该库使用 pandas DataFrames 来存储生理时间序列。我一直在不同的计算设置中使用这个库。当我尝试在我的 ubuntu 15.10 环境中使用它时,我收到一条我不理解的错误消息。它与以下函数相关,该函数有助于将数据放入 DataFrame 并进行一些初始转换:
def loadData_E4(filepath):
# Load data
data = pd.DataFrame.from_csv(os.path.join(filepath,'EDA.csv'))
data.reset_index(inplace=True)
# Get the startTime and sample rate
startTime = pd.to_datetime(float(data.columns.values[0]),unit="s")
sampleRate = float(data.iloc[0][0])
data = data[data.index!=0]
data.index = data.index-1
这会导致以下错误消息:
In [1]:
run batch_edaexplorer_template.py
Classifying data for ...[my file location]...
---------------------------------------------------------------------
TypeError Traceback (most recent call last)
/...mypath/eda-explorer-master/batch_edaexplorer_template.py in <module>()
69 elif dataType=='e4':
70 print "Classifying data for " + filepath
---> 71 labels,data = classify(filepath,classifierList,pickleDirectory,lf.loadData_E4)
72 elif dataType=="misc":
73 print "Classifying data for " + filepath
/...mypath/eda-explorer-master/EDA_Artifact_Detection_Script.pyc in classify(filepath, classifierList, pickleDirectory, loadDataFunction)
225
226 # Load data
--> 227 data = loadDataFunction(filepath)
228
229 # Get pickle List and featureNames list
/...mypath/eda-explorer-master/load_files.pyc in loadData_E4(filepath)
58 sampleRate = float(data.iloc[0][0])
59 data = data[data.index!=0]
---> 60 data.index = data.index-1
61
62 # Reset the data frame assuming 4Hz samplingRate
/usr/lib/python2.7/dist-packages/pandas/core/index.pyc in __sub__(self, other)
1161 warnings.warn("using '-' to provide set differences with Indexes is deprecated, "
1162 "use .difference()",FutureWarning)
-> 1163 return self.difference(other)
1164
1165 def __and__(self, other):
/usr/lib/python2.7/dist-packages/pandas/core/index.pyc in difference(self, other)
1314
1315 if not hasattr(other, '__iter__'):
-> 1316 raise TypeError('Input must be iterable!')
1317
1318 if self.equals(other):
TypeError: Input must be iterable!
我的 windows PC 上没有收到此错误消息。我在 ubuntu 环境中使用 pandas 版本 0.15.0。这可能是与索引相关的特定语法只允许在 pandas 的更高版本中使用的问题吗?我应该如何更正语法以使其适用于旧版本的 pandas?还是我没抓住要点?
尝试 data.index = pd.Index(data.index.values-1)
而不是 data.index = data.index-1
。