0

I have one time series df containing various stock market data (i.e. date, symbol, open, close..ect) and another with metadata containing the symbol and name of the stock.

I would like to create a new column in the df with the stocks name using the symbol as a match. How would I go about this?

I've tried using pd.merge based on symbol, but the resulting column was populated with Nan's.

Df:

Date Open Close Symbol
06/18 4.80 4.79 SPXB

Names df:

Name Symbol
Ace SPXB

And what I would like is:

Date Open Close Symbol Name
06/18 4.80 4.79 SPXB Ace
mozway
  • 194,879
  • 13
  • 39
  • 75
tay-c
  • 1
  • 1
  • Please provide a [minimal reproducible example](//stackoverflow.com/help/minimal-reproducible-example), see specific details on [how to make good reproducible pandas examples](//stackoverflow.com/q/20109391/16343464). – mozway May 01 '23 at 22:40
  • `df1['Name'] = df1['Symbol'].map(df2.set_index('Symbol')['Name'])` – mozway May 01 '23 at 22:48
  • 1
    Thank you! That worked exactly as I had hoped – tay-c May 01 '23 at 22:57

0 Answers0