I want to merge two dataframes. But when I do the following I got KeyError: "['available'] not in index"
. I looked at Python Pandas merge only certain columns . But what I'm doing wrong?
d = { 'listing_id': [1,2,3,4],
'month': [1, 2, 3, 4],
'price': [79.00, 80.00, 90.00, 20.00]}
df = pd.DataFrame(data=d)
d2 = {'id': [1, 2, 3, 4],
'available': [5000, 8000,5000, 7000],
'someotherstuff': [2,3,4,5]}
df2 = pd.DataFrame(data=d2)
df = pd.merge(df,df2[['id','available']],on='listing_id', how='left')
What I want
listing_id month price available
0 1 1 79.0 5000
1 2 2 80.0 8000
2 3 3 90.0 5000
3 4 4 20.0 7000