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
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.
you can drop the duplicates like this.
df = df.drop_duplicates()
you can try:
df = df[df['a'] != df['b']]
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)
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
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.
you can drop the duplicates like this.
df = df.drop_duplicates()
you can try:
df = df[df['a'] != df['b']]
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)