1
Given the following Dataframes:
df = pd.DataFrame([[1, 2, 1], [4, 5, 2], [1, 2 , 3]],
columns=['coluna1', 'coluna2','id'])
df2 = pd.DataFrame([[1, 7, 1], [4, 'a', 2], [1, 'abc', 3]],
columns=['coluna3','coluna4', 'id'])
I want to merge between them but only bringing the column3 of df2
In case I use:
df = df.merge(df2['coluna3','id'], on='id', how='left')
I get the following error:
Keyerror: ('coluna3', 'id')
But if instead of using only one bracket ( [] ) to select the columns I want, I use two ( [[]] ), it works normally, why this??
df = df.merge(df2[['coluna3','id']], on='id', how='left')