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

Matthijs Noordzij picture Matthijs Noordzij · Jul 20, 2016 · Viewed 9.5k times · Source

I'm working with the eda-explorer python library from MIT, which allows one to import physiological data files from particular wearable biosensors. This libraray uses pandas DataFrames to store the physiological timeseries. 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. It is related to the following function which is instrumental in getting the data into a DataFrame and doing some intitial transformations:

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. I'm using pandas version 0.15.0 in the ubuntu environment. 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? Or am I missing the point?

Answer

Alberto Garcia-Raboso picture Alberto Garcia-Raboso · Jul 20, 2016

Try data.index = pd.Index(data.index.values-1) instead of data.index = data.index-1.