Apologies if my question has been answered before, or the answer is obvious.
Let's say that in my dataset there are two tasks, 20 different trials each. Now I would like to select only last 6 seconds of each trial for further analysis.
The dataset looks sort of like this (+more columns). This sample covers all 20 trials of one task. Index values are as in the full dataset, time is given in unix timestamps (ms).
index   time                x           y          Trial_Id
13512   1519227368636.0000  1022.0000   602.0000    1
13513   1519227368683.0000  1019.0000   697.0000    1
13514   1519227368728.0000  966.0000    530.0000    1
13515   1519227368752.0000  961.0000    576.0000    1
13516   1519227368806.0000  1120.0000   631.0000    1
...
17076   1519227518503.0000  804.0000    694.0000    20
17077   1519227518549.0000  789.0000    738.0000    20
17078   1519227518596.0000  809.0000    747.0000    20
17079   1519227518678.0000  806.0000    735.0000    20
17080   1519227518713.0000  823.0000    605.0000    20
On the level of single trial iloc does the job. However, when I try to apply iloc on the data grouped by trial_Id, I get the error:
TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed.
The code I use:
a function to preserve the last 6 seconds
def img_trial(data, start): data1 = data.iloc[start:-1,:] return data1
a function application on data grouped by trial
data.groupby(['Trial_Nr']).apply(img_trial(data, 80))
Can you please give me a hint on what's wrong? I'm quite a pandas-newbie. Sorry if my question is not clear enough (that's the first post of a long time lurker).
Best regards,
Nat
 
    