0

image of two dataframes enter image description here

I would like to add to create the column new_column with the corresponding values from the second data frame.

desired outcome - but with matching values in column enter image description here

EdChum
  • 376,765
  • 198
  • 813
  • 562
qtmspin
  • 109
  • 3
  • 7
  • 5
    Please post text rather than images, also I think this should work: `df['new_column'] = other_df['Equity(24 AAPL)']` – EdChum Dec 10 '15 at 21:44
  • Please follow: [How to make good reproducible pandas examples](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – Kartik Dec 10 '15 at 23:59
  • Thanks for the link, I was struggling on how to explain my question. – qtmspin Dec 11 '15 at 13:01

1 Answers1

0
df_sp_500_long = pd.melt(df_sp_500_long.reset_index(), 
                         id_vars='date', var_name='symbol', 
                         value_name='new_column')

(first_df
 .reset_index()
 .merge(df_sp_500_long, on=['date','symbol'], how='left'))
attitude_stool
  • 1,023
  • 1
  • 13
  • 18