So basically I have a Pandas dataframe named “data” in which:
The first column contains all values from start to end of a recording timestamp;
A variable number of columns contains values in the form of “-1”, “0” or “1”.
Except for the timestamp column (named RecordingTimestamp) all other columns share part of the name. Specifically, all columns are named AOI[***]Hit, where the asterisks stand for the variable part of the name between the square brackets.
What I’d like to do with this data is loop through all the columns, find for each of them the timestamp corresponding to the first “0” (ts 0) and the first “1” (ts 1) and get the result of the subtraction ts1-ts0.
Up to now I managed to create a very basic script that does this only for one column.
Here it is:
ts = data[‘RecordingTimestamp’]
aoi = data[‘AOI[info_text]Hit’]
t1 = np.where(aoi == 0)
t1 = t1
t2 = np.where(aoi == 1)
t2 = t2
for i in data[‘AOI[info_text]Hit’]:
if i == 0:
val1 = t1
elif i == 1:
val2 = t2
What I’d like it to do eventually is loop through all the columns and print for each of them the name (taken from what’s between the square brackets) and the result of the subtraction (maybe in the form of an ordered dictionary). PLEASE NOTE: if the columns does not contain any “1”, instead of the result of the subtraction ts1-ts0 a string should be printed.
I can’t figure out how to create this kind of loop and any help would be really appreciated.