How calculate a value using a previous values in pandas dataframe
Question:
I am trying to calculate a value in a pandas dataframe using the previous value. Given the values below:
year
sex
age
pxt
lxt
2000
m
0
m
x
2000
m
1
n
y
2000
m
2
o
z
x = 1 (by definition)
y = x * m
z = y * n
I tried to use the .shift(1) method, which worked for the pxt, but since the lxt is calculated iterativly, this did not work in this case.
And yes, data are grouped by year and sex.
Thank you very much!
Answers:
I am trying to calculate a value in a pandas dataframe using the previous value. Given the values below:
year | sex | age | pxt | lxt |
---|---|---|---|---|
2000 | m | 0 | m | x |
2000 | m | 1 | n | y |
2000 | m | 2 | o | z |
x = 1 (by definition)
y = x * m
z = y * n
I tried to use the .shift(1) method, which worked for the pxt, but since the lxt is calculated iterativly, this did not work in this case.
And yes, data are grouped by year and sex.
Thank you very much!