How do I get the percentage change of values ββin a dataframe while keeping NaN values?
I have the following DataFrame:
Date A
2015-01-01 10
2015-01-02 14
2015-01-05 NaN
2015-01-06 NaN
2015-01-07 5
2015-01-10 1
2015-01-11 NaN
2015-01-12 21
2015-01-14 13
And I would like to receive a dataframe with pct change in a dataframe only if the two values ββare adjacent and not separated by NaN.
i.e. I would like to:
Date A
2015-01-02 0.2857
2015-01-10 -0.8
2015-01-14 -0.38
But if I do this : df.pct_change()
, it will return the pct change between 14 and 5 for 201-01-07
+3
source to share
2 answers