I have a dataframe where rows represents dates or minutes, and their corresponding values for each.
Is it possible for pandas to first (1) detect a increase in value, (2) then goes flat for x number of rows, (3) then increases again?
For e.g, in the image below, at 0934 value is 8.135. It increases to 8.18 and stays there until 0941, seven rows later. it then increases again to 0.185 at 0942am.
This group of rows needs to be identified with a 1 at the end of such a group. Referring to the earlier example, the desired output is 1 at 0942am.
Note that the increaseing plateaus is just for illustration, not to be in the actual dataframe. The code needs to find the "values" column amongst the 30+ other columns in the dataframe, process the column to find the plateaus and output to a new column called "desired output".
And the numbers under the value column do not just increase, may decrease as well. No set pattern, just that in this case an event occurred causing the numbers to go up. At least two of the same values are needed across two rows to be considered a plateau.
The closest example I can find here is the following, but the solutions seem to involve sorting the columns, which I cannot in this case as the rows are representing time.
I'm still learning python and can write something like below, but I'm do not know where to start for the above case. Please advise!
Will be great if the above case can be solved using numpy or some other fast method!
def check2(df):
df.loc[:, 'check2'] = np.where((df.open > df.close) & (df.close.shift(1) > df.open.shift(1)),
np.where((df.open > df.close.shift(1)) & (df.close < df.open.shift(1)), 1, 0), 0)
return df
