For questions about contributing to pandas, please ask in the pandas-dev/community channel
Florian
Hi there, can anyone help me with a seamingly simple task?
I have the following DataFrame:
Participant Time Value
0 1 1 1
1 1 2 2
2 1 3 3
3 2 1 2
4 2 2 5
5 2 3 7
And now I want to subtract the Value at Time==1 from the Value at Time==2 and Time==3, such that the DataFrame becomes:
Participant Time Value
0 1 1 0
1 1 2 1
2 1 3 2
3 2 1 0
4 2 2 3
5 2 3 5
I just cannot figure out how to do this :-)
kir0ul
> <@fladd:matrix.org> Hi there, can anyone help me with a seamingly simple task?
I have the following DataFrame:
Participant Time Value 0 1 1 1 1 1 2 2 2 1 3 3 3 2 1 2 4 2 2 5 5 2 3 7
And now I want to subtract the Value at Time==1 from the Value at Time==2 and Time==3, such that the DataFrame becomes:
Participant Time Value 0 1 1 0 1 1 2 1 2 1 3 2 3 2 1 0 4 2 2 3 5 2 3 5
I just cannot figure out how to do this :-)
Maybe this can help?
https://stackoverflow.com/questions/34855859/is-there-a-way-in-pandas-to-use-previous-row-value-in-dataframe-apply-when-previ
Florian
kir0ul: Thanks for the pointer. However, this does not seem to work. I do:
for i in range(1, len(data)):
time = data.loc[i, "Time"]
if time != 1:
data.loc[i, "Time"] = data.loc[i, "Time"] - data.loc[i-time-1, "Time"]
But I get the error:
KeyError: 'the label [-2] is not in the [index]'
Florian
ha, paranthesis error :-)
Florian
but it still does not work. I creates the original data frame, instead of the subtracted one