Monday 30 November 2020

How to count the number of consecutive days a value grows

I have the following df:

Date
2015-11-27    105.449997
2015-11-30    104.239998
2015-12-01    107.120003
2015-12-02    106.070000
2015-12-03    104.379997
                 ...    
2020-11-18    271.970001
2020-11-19    272.940002
2020-11-20    269.700012
2020-11-23    268.429993
2020-11-24    276.920013
Name: Close, Length: 1258, dtype: float64

What I am trying to do is find for how many days in a row has the Close closed lower than the previous day. Could you please advise how I can go about this?

For example: enter image description here

At this point it would say Close was lower for the last 3 days on Date

    Date          Close     Days
    10/30/2020  263.109985  0.0
    11/2/2020   261.359985  1.0
    11/3/2020   265.299988  0.0
    11/4/2020   287.380005  1.0
    11/5/2020   294.679993  0.0
    11/6/2020   293.410004  1.0
    11/9/2020   278.769989  0.0
    11/10/2020  272.429993  1.0
    11/11/2020  276.480011  0.0
    11/12/2020  275.079987  1.0
    11/13/2020  276.950012  0.0
    11/16/2020  278.959991  0.0
    11/17/2020  275.000000  1.0
    11/18/2020  271.970001  2.0
    11/19/2020  272.940002  0.0
    11/20/2020  278.000000  1.0
    11/23/2020  277.000000  2.0
    11/24/2020  276.920013  3.0

How can achieve this?



from How to count the number of consecutive days a value grows

No comments:

Post a Comment