I want monotonic trend of a variables. Data looks like:
Output is required in the form of:
I have tried to iterate over rows using apply but got no luck. I have also tried is_monotonic_increasing and is_monotonic_decreasing from pandas.
Thanks in advance for your help.
pd.Series.is_monotonic_decreasing
can work for your case.I would first
pivot
the dataframe in order to get each varaible in a column, then for each column dropnan
s (otherwiseis_monotonic_decreasing
will always returnFalse
), apply bothis_monotonic_decreasing
andis_monotonic_increasing
and collect the results: