0

I have two dataframes; df1 and df2

df1 looks like this:

enter image description here

df2 looks like this:

enter image description here

My aim is to join df1 and df2 based on three keys: city, Year and Asset_Type as follows:

Index_step1=pd.merge( df1, df2[['city','Year','Asset_Type','psqm_city','city_returns']] , right_on =['city','Year', 'Asset_Type'], left_on=['city','Year','Asset_Type'], how = 'right')

My aim is to have the values of the Year 2021 appear in the output Index_step1 (2021 appear in df2 but not in df1). The right_join should keep the rows of the right dataframe (df2) but i am puzzled as to why the values of the Year 2021 do not appear in the output which looks like this (see below). I also tried outer join but the values of Year 2021 still do not appear there. Any idea what i am missing here? Thanks

Index_step1

enter image description here

bravopapa
  • 309
  • 1
  • 10

1 Answers1

1

Yeah looks like a bug and I'm gonna recommend a weird thing can you try to write left_on paramater first then right_on cause it seems like your function is doing left join not right join

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 02 '23 at 13:31
  • Thanks for the suggestion. It is still not working... outer join should work as well (it worked in other places) – bravopapa Jan 02 '23 at 13:36