0

I have a problem updatding a column value from a second dataframe that is a dictiorany/catalog.

This is my main dataframe (df)

df dataframe

and the dictionary dataframe (dictionary)

dictionary dataframe

I want to update the column df.City of the main df from the dictionary with the condition where df.id_state = dictiorary.ID_State and df.ID_City = dictionary.Id_City.

I don't know how to do that with a dictionary with 3 columns. I already did it with a normal dictionary of 2 columns.

rename_dict_E = df_Ent.set_index('ID_State').to_dict()['State'] df_CovidMx.ID_State = df_CovidMx.ID_State.replace(rename_dict_E)

I hope somebody can give me a hand!

Regard. Im learning Python

  • `df1[['Id_State', 'ID_City']].merge(df2.rename(columns={'ID_State': 'Id_State'}), how='left', on =['Id_State', 'ID_City'] )` – ansev Apr 24 '20 at 17:50
  • Thanks Ansev, that was the soluction. df1= pd.merge(df1,df2, how='left', on =['Id_State', 'Id_City'] ) – user3085584 Apr 25 '20 at 01:27

0 Answers0