重复值的熊猫

时间:2019-09-18 12:18:19

标签: pandas pandas-groupby pandasql pandas-apply pandas-profiling

2 个答案:

答案 0 :(得分:1)

IIUC,这就是您所需要的

a = (df['A'].ne(df['A'].shift())).ne((df['B'].ne(df['B'].shift())))
df[~a].reset_index(drop=True)

输出

    A   B
0   2   z
1   3   x
2   3   x

答案 1 :(得分:1)

我认为您需要:

cond=(df.eq(df.shift(-1))|df.eq(df.shift())).all(axis=1)
pd.concat([df[~cond].groupby('A').last().reset_index(),df[cond]])

    A   B
0   2   y
2   3   x
3   3   x