I have a dataframe detailing some statistics of store revenues:
#Create data
data = {'Day': [1,1,2,2,3,3],
'Where': ['A','B','A','B','B','B'],
'What': ['x','y','x','x','x','y'],
'Dollars': [100,200,100,100,100,200]}
index = range(len(data['Day']))
columns = ['Day','Where','What','Dollars']
df = pd.DataFrame(data, index=index, columns=columns)
df
and a dataframe with some informations on the stores (longitude and latitude let's say):
Create data
data = {'Where': ['A','B'],
'Lon': [10,11],
'Lat': [20,22]}
index = range(len(data['Where']))
columns = ['Where','Lon','Lat']
df2 = pd.DataFrame(data, index=index, columns=columns)
df2
I want to add the information of the second dataframe into the first one. My best try was:
df3=df
df3['Lon'] = df2[df2.Where == df.Where, 'Lon']
but this throws an error:
ValueError: Can only compare identically-labeled Series objects
What is the correct way of doing this?