Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何从两列中的值为sam的Dataframe中删除行?_Python_Pandas_Dataframe_Remove_Drop - Fatal编程技术网

Python 如何从两列中的值为sam的Dataframe中删除行?

Python 如何从两列中的值为sam的Dataframe中删除行?,python,pandas,dataframe,remove,drop,Python,Pandas,Dataframe,Remove,Drop,我的DF如下所示 Date New_date X Y 01-12 01-12 3 4 01-13 01-13 6 1 01-14 01.15 2 3 我需要这个结果: Date New_date X Y 01-14 01.15 2 3 o代码应删除前两行,因为列Date和New_Date中的值相同。我试过这个: df.drop(df.loc[df['Date'] == df['New_date']]) 但它不起作用。有什么想法吗 向您致以

我的DF如下所示

Date   New_date X  Y
01-12  01-12    3  4
01-13  01-13    6  1
01-14  01.15    2  3
我需要这个结果:

Date   New_date X  Y
01-14  01.15    2  3
o代码应删除前两行,因为列Date和New_Date中的值相同。我试过这个:

df.drop(df.loc[df['Date'] == df['New_date']])
但它不起作用。有什么想法吗

向您致以最诚挚的问候并感谢您的帮助


更改逻辑-如果值不相等,则获取所有行

因此,将
==
更改为
=用于不相等的值,并过滤入:


你让我高兴极了,兄弟。谢谢
df = df.drop_duplicates(subset=['Date', 'New_date'], keep=False)
df = df[df['Date'] != df['New_date']]
print (df)
    Date New_date  X  Y
2  01-14    01.15  2  3