Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python Pandas : joining selective columns from 1 data frame and add to another

I want to take 1 column from dataframe ‘dfGS’ and add it to dataframe ‘df3’

If I just join the full dfGS to DF3 it works fine, but when I try to specify only 1 column to join I get : KeyError:’Ticker’**

”’df3=pd.merge( df3,dfGS[‘Shares to Trade’],how="inner",on=’Ticker’)”’

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Ticker is the correct reference column in both df’s , so not sure where I am going wrong?

error
df3

dfGS

>Solution :

I would do it like this:

df3 = df3.merge(dfGS[['Shares to Trade',"Ticker"]], how="inner", left_on="Ticker", right_on="Ticker")

OR

df3 = df3.merge(dfGS[['Shares to Trade',"Ticker"]], how="inner", on="Ticker")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading