简体   繁体   English

删除一列中具有相同值而另一列中具有不同值的行

[英]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.

相关问题 选择在一列中具有相同值而在另一列中具有不同值的行 Pandas Python - Select rows with equal values in one column and different values in another column Pandas Python Pandas - 在另一列中具有相同值的行中的一列中查找重复条目 - Pandas - Find duplicated entries in one column within rows with equal values in another column 如果值等于某个数字,则将值从一列复制到另一列 - Copy values from one column to another if values equal to a certain number 将过滤后的数据帧行的值设置为等于另一个数据帧的列 - Setting the values of filtered rows of dataframe equal to the column of another dataframe 删除熊猫中所有具有同一列值而另一列具有不同值的行 - Dropping all rows in pandas having same values in one column and different values in another 从一列中删除等于另一列中的值的值 - Remove values from one column, that are equal to the value in another 将一列中选定行的值除以另一列 - Divide values from selected rows from one column by another column 将一列中的值替换为另一列中的值 - Replacing values in one column with values in another column 当另一个列的值与 NaN 不同时打印第 1 列的值 - print values of column 1 when values of another one are different from NaN 如何删除具有相同列功能值的行,以保留保留已删除行另一功能的所有值的一行? - How to delete rows that share the same value of a column feature to make one row which keeps all the values of another feature of the deleted rows?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM