I Have Two Dataframes df
and ds
import pandas as pd
ds = pd.DataFrame({'Price': {0: 1200, 1: 1400, 2: 1500,
3: 1800},
'Time(s)': {0: 500, 1: 500, 2: 600,
3: 500},
'id': {0: 'a01', 1: 'a02', 2: 'a03',
3: 'a04'}})
df = pd.DataFrame({'Price': {0: 1200, 1: 1500, 2: 1450,
3: 1800, 4: 1200},
'Time(s)': {0: 500, 1: 500, 2: 500,
3: 500, 4: 500},
'id': {0: 'a01', 1: 'a02', 2: 'a03',
3: 'a04', 4: 'a05 '}})
ds Output:
Price Time(s) id
1200 500 a01
1400 500 a02
1500 600 a03
1800 500 a04
df Output:
Price Time(s) id
1200 500 a01
1500 500 a03
1450 500 a02
1800 500 a04
1200 500 a05
Desired Output:
df1:
Price Time(s) id
1200 500 a05
I want to compare them, anf if there same values in id
column in both datframes drop them, and outcome save into new dataframe df1
, i tried to:
df1 = pd.concat([ds,df])
and
df1.drop_duplicates(subset='id',keep='last')
But The Values were the same