2

I have the following two dataframes:

df1:

Symbol, Open, High, Low, Close
abc,    123,  676,  100, 343

df2:

Symbol, Target1, Target2
abc,    654,     565

I am trying to combine these two dataframes based on symbol, ie: Target1/Target2 must be added as new columns:

Symbol, Open, High, Low, Close, Target1, Target2
abc,    123,  676,  100, 343,   654,     565

I have tried a some join/merge ideas but can't seem to get it to work.

Please can someone advise.

1 Answer 1

3

Just concat them and pass param axis=1:

In [7]:

pd.concat([df,df1], axis=1)
Out[7]:
  Symbol  Open  High  Low  Close Symbol  Target1  Target2
0    abc   123   676  100    343    abc      654      565

Or merge on 'Symbol' column:

In [8]:

df.merge(df1, on='Symbol')
Out[8]:
  Symbol  Open  High  Low  Close  Target1  Target2
0    abc   123   676  100    343      654      565
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.