The following code adds x after Name and Price as well as two additional columns Name_y and Price_y. How can I remove these items?
import pandas as pd df = pd.DataFrame ({ 'IP':['1.1.1.1','2.2.2.2','3.3.3.3','4.4.4.4','5.5.5.5'], 'ID':['101','202','303','404','505'], 'Name':['aqua','noctua','ytube','tech','logi'], 'Price':[100,200,300,400,500] }) df1 = pd.DataFrame ({ 'IP':['1.1.1.1','2.2.2.2','3.3.3.3','4.4.4.4','6.6.6.6'], 'ID':['101','202','303','404','606'], 'Name':['atlas','noctua','ytube','tech','smash'], 'Price':[600,700,800,900,990] }) print(df) IP ID Name Price 0 1.1.1.1 101 aqua 100 1 2.2.2.2 202 noctua 200 2 3.3.3.3 303 ytube 300 3 4.4.4.4 404 tech 400 4 5.5.5.5 505 logi 500 print(df1) IP ID Name Price 0 1.1.1.1 101 atlas 600 1 2.2.2.2 202 noctua 700 2 3.3.3.3 303 ytube 800 3 4.4.4.4 404 tech 900 4 6.6.6.6 606 smash 990 new=df1.merge(df,indicator=True,how='left', on=['IP', 'ID']).loc[lambda x : x['_merge']=='left_only'].drop('_merge',1) print(new) IP ID Name_x Price_x Name_y Price_y 4 6.6.6.6 606 smash 990 NaN NaN The expected result is:
IP ID Name Price 4 6.6.6.6 606 smash 990 I simply don't know what needs to be changed... Thank you!