2

My DF looks like below

Date   New_date X  Y
01-12  01-12    3  4
01-13  01-13    6  1
01-14  01.15    2  3

I need this result:

Date   New_date X  Y
01-14  01.15    2  3

o code should remove first 2 rows because values in columns Date and New_date are the same. I tried with this:

df.drop(df.loc[df['Date'] == df['New_date']])

But it doesn't work. Any idea?

Best regards and thanks for help

Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63
Tmiskiewicz
  • 389
  • 1
  • 11

2 Answers2

1

Use pd.DataFrame.drop_duplicates

df = df.drop_duplicates(subset=['Date', 'New_date'], keep=False)
Vishnudev Krishnadas
  • 10,679
  • 2
  • 23
  • 55
1

Change logic - get all rows if not equal values.

So change == to != for not equal values and filter in boolean indexing:

df = df[df['Date'] != df['New_date']]
print (df)
    Date New_date  X  Y
2  01-14    01.15  2  3
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252