0

I have a pd.DataFrame and want to check if the second value is higher then the first, the third higher then the second and so on. After I checked the DataFrame I want to make sure that at least 80% of the Values are Higher. Before that I want to remove the value with the same value as the one before. Example: df = pd.DataFrame([1,2,3,5,5,6,7,7,5]) black = remove.

import pandas as pd

df = pd.DataFrame([1,2,3,5,5,6,7,8,9,10])
diff = df[0] - df[0].shift(1)
increasing = (diff <= 0).sum() <= 0.2 * len(df)
if increasing :
    print ("increasing")
    
decreasing = (diff >= 0).sum() <= 0.2 * len(df)
if decreasing :
    print("decreasing")
    
if increasing == False and decreasing == False:
    print("more or less constant")

1 Answers1

0

Use:

df = df[df[0].ne(df[0].shift())]
print (df)
   0
0  1
1  2
2  3
3  5
5  6
6  7
8  5
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252