0

I would like to load and modify individual datasets and afterwards store them in a single array. As there are many datasets, I would like to build a loop to not write the same code for every dataset. However, I didn't find a solution of how to address the names of my data with a loop. The individual datasets are called e01, e02, e03, ....

I've tried to use a for-loop, but therefore I have to put the names of the datasets as strings in a list. This doesn't work, as the loop only accesses the strings, but not the data behind the names. This is the basic operation I want to put in the for-loop:

e01=np.delete(e01,0,1) #delete the first column
test = np.full(len(e01), 1) #create array with participant number
e01 = np.column_stack((e01,test)) #add an additional column that contains the participant number
e02=np.delete(e02,0,1)
test = np.full(len(e02), 2) #create array with participant number
e02 = np.column_stack((e02,test))

Also, I tried to concatenate the data in a loop, but as the first line has to be different I don't know how to start the loop:

e_data = np.append(e01,e02,axis=0)
e_data = np.append(e_data,e03,axis=0)
e_data = np.append(e_data,e04,axis=0)
Melanie
  • 13
  • 4

1 Answers1

0

locals() returns a dictionary of variables in the current scope. You can then access the variable names as strings:

In [14]: e01='hi'

In [15]: e02='there'

In [16]: e03=[1,2,42]

In [17]: for i in range(3):
    ...:     print locals()['e0%d'%(i+1)]
    ...:

hi
there
[1, 2, 42]
rcriii
  • 687
  • 6
  • 9