我有一个pd。并希望检查第二个值是否高于第一个值,第三个值是否高于第二个值,依此类推。在我检查了DataFrame之后,我想确保至少80%的值是更高的。在此之前,我想要删除与前一个值相同的值。例如:df = pd。DataFrame ([1, 2, 3, 5,5<6 7日em>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")
使用说明:
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