简体   繁体   English

python pandas dataframe index,错误TypeError:输入必须可迭代,熊猫版本可能错误

[英]python pandas dataframe index, error TypeError: Input must be iterable, pandas version perhaps wrong

I'm working with the eda-explorer python library from MIT, which allows one to import physiological data files from particular wearable biosensors. 我正在使用MIT的eda-explorer python库,该库允许从特定的可穿戴生物传感器导入生理数据文件。 This libraray uses pandas DataFrames to store the physiological timeseries. 这个天秤座使用pandas DataFrames存储生理时间序列。 I've been using this libarary in different computing set-ups. 我一直在不同的计算设置中使用此库。 When I try to use it in my ubuntu 15.10 environment I get an error message I don't understand. 当我尝试在ubuntu 15.10环境中使用它时,出现一条我不理解的错误消息。 It is related to the following function which is instrumental in getting the data into a DataFrame and doing some intitial transformations: 它与以下功能相关,该功能有助于将数据放入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

This results in the following error messages: 这将导致以下错误消息:

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!

I don't get this error message on my windows PC. 我在Windows PC上没有收到此错误消息。 I'm using pandas version 0.15.0 in the ubuntu environment. 我在ubuntu环境中使用的是熊猫版本0.15.0。 Is this perhaps the problem that the particular syntax related to the index is only allowed in higher versions of pandas? 这是否可能是仅在更高版本的熊猫中允许与索引相关的特定语法的问题? How should I correct the syntax so that it works with older version of pandas? 我应该如何更正语法,使其与较早版本的pandas一起使用? Or am I missing the point? 还是我错过了重点?

尝试使用data.index = pd.Index(data.index.values-1)而不是data.index = data.index-1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM