I am trying to find the number of consecutive green closing prices from a dataframe before a certain date.
Input:
Ticker Date Close
0 AAPL 20200501 1.5
1 AAPL 20200502 1.2
2 AAPL 20200503 1.3
3 AAPL 20200504 1.3
4 AAPL 20200505 1.4
5 AAPL 20200506 1.5
In this example I would want to know the consecutive closing prices that were higher than the previous day's closing prices on 20200507
Desired output:
2
Here is the code for the example dataframe
import pandas as pd
df1 = pd.DataFrame({'Ticker': ['AAPL', 'AAPL', 'AAPL', 'AAPL', 'AAPL', 'AAPL'],
'Date': [20200501, 20200502, 20200503, 20200504, 20200505, 20200506],
'Close': [1.5, 1.2, 1.3, 1.3, 1.4, 1.5]})
print(df1)