Remove rows with similar values

Question:

I want to remove all rows where Column "a" value = Column "b" value from the DataFrame like this:

    a   b
1 AAA BBB
2 AAA CCC
3 AAA AAA
4 CCC CCC
5 CCC BBB
6 CCC DDD

Desired output:

     a  b
1 AAA BBB
2 AAA CCC
3 CCC BBB
4 CCC DDD
Asked By: Vlad Fedo

||

Answers:

In [93]: df.loc[df.a.ne(df.b)]
Out[93]:
     a    b
1  AAA  BBB
2  AAA  CCC
5  CCC  BBB
6  CCC  DDD

keep the rows where "a" values are not equal to the "b" values.

Answered By: Mustafa Aydın

you can drop the duplicates like this.

df = df.drop_duplicates()
Answered By: Shahin Ramezanzade

you can try:

df = df[df['a'] != df['b']]
Answered By: risper

df_filtered = df[df['a'] = df['b']]

or if you want to drop the rows then

df.drop(df[df['a'] = df['b']].index, inplace = True)

Answered By: Ashutosh Mittal