[英]Delete rows with equal values in one column and different values in another column
I have a dataframe that has repeated values in one column (col_a) and repeated values in another column (col_b).我有一个 dataframe 在一列 (col_a) 中有重复值,在另一列 (col_b) 中有重复值。
I want to select only the rows that have the same value in one column (col_a) but different values in another column (col_b).我只想 select 仅在一列 (col_a) 中具有相同值但在另一列 (col_b) 中具有不同值的行。
Original dataframe原装 dataframe
col_a col_b col_c
0 1 2 1
1 1 2 1
2 3 20 1
3 3 18 1
4 3 20 1
5 3 18 1
Desired dataframe所需 dataframe
col_a col_b col_c
2 3 20 1
3 3 18 1
4 3 20 1
5 3 18 1
I've tried using df.duplicate but it doesn't work because I have duplicate values in both columns.我试过使用 df.duplicate 但它不起作用,因为我在两列中都有重复的值。 I want to select only the rows that have different values in column b but equal values in column a.
我只想 select 在 b 列中具有不同值但在 a 列中具有相等值的行。
You can do something like this.你可以做这样的事情。
df[df["col_a"] != df["col_b"]]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.