how to find number of consecutive decreases(increases)
I have a dataframe which has 500K rows and 12 columns for months and include start and end month. Every columns re
So I think instead of using argmin
, you can use idxmin after renaming the column to get an integer value of the position. Then remove the value of the startMonth
such as:
incr = (df1.rename(columns={col:int(col.split('_')[1]) for col in masked.columns})
.diff(-1, axis=1) < 0).mask(~arr_bool).idxmin(axis=1) - startMonth.start
decr = (df1.rename(columns={col:int(col.split('_')[1]) for col in masked.columns})
.diff(-1, axis=1) > 0).mask(~arr_bool).idxmin(axis=1) - startMonth.start
Then you can do the np.select
as you do, or probably just a .illna(-999)
should be enough as I think with this solution everywhere you have nan in the result will be where your condition startMonth.start > endMonth.end
is met