0

I have two dataframes:

>>>import import pandas as pd
>>>df1:

                 DD_PRICE
DATE                         
2013-09-19 20:55:00  3.516
2013-09-19 20:55:00  3.516
2013-09-19 20:55:00  3.516
2013-09-19 20:55:00 -4.476

>>>df2:
                 CAPI_PRICE
DATE                         
2013-09-19 20:55:00  3.516
2013-09-19 20:55:00  3.516
2013-09-19 20:55:00  3.516
2013-09-19 20:55:00 -4.476

Now when I run:

 joint_df = df1.join((df2), how='outer')

joint_df looks like this:

                  DD_PRICE  CAPI_PRICE
DATE                                   
2013-09-19 20:55:00  3.516  3.516
2013-09-19 20:55:00  3.516  3.516
2013-09-19 20:55:00  3.516  3.516
2013-09-19 20:55:00  3.516 -4.476
2013-09-19 20:55:00  3.516  3.516
2013-09-19 20:55:00  3.516  3.516
2013-09-19 20:55:00  3.516  3.516
2013-09-19 20:55:00  3.516 -4.476
2013-09-19 20:55:00  3.516  3.516
2013-09-19 20:55:00  3.516  3.516
2013-09-19 20:55:00  3.516  3.516
2013-09-19 20:55:00  3.516 -4.476
2013-09-19 20:55:00 -4.476  3.516
2013-09-19 20:55:00 -4.476  3.516
2013-09-19 20:55:00 -4.476  3.516
2013-09-19 20:55:00 -4.476 -4.476

This isnt what I want...

Ideally I want joint_df to look like this:

                  DD_PRICE  CAPI_PRICE
DATE                                   
2013-09-19 20:55:00  3.516  3.516
2013-09-19 20:55:00  3.516  3.516
2013-09-19 20:55:00  3.516  3.516
2013-09-19 20:55:00 -4.476 -4.476

How do I get this done? Tried different combos of merge and join parameters but I can't get it to work!

2
  • 1
    You have duplicate index. If the order of index in both dataframes always same, use df1['CAPI_PRICE'] = df2['CAPI_PRICE'].values? Commented Oct 4, 2017 at 12:23
  • df = pd.concat([df1, df2], axis=1) does not work? Commented Oct 4, 2017 at 12:27

2 Answers 2

1

It seems you can use concat only - by default there is outer join:

df = pd.concat([df1, df2], axis=1)
print (df)
                     DD_PRICE  CAPI_PRICE
DATE                                     
2013-09-19 20:55:00     3.516       3.516
2013-09-19 20:55:00     3.516       3.516
2013-09-19 20:55:00     3.516       3.516
2013-09-19 20:55:00    -4.476      -4.476
Sign up to request clarification or add additional context in comments.

Comments

0

You could try to just add a new column on first data frame by copying it from second data frame like this:

df1['CAPI_PRICE']=df2['CAPI_PRICE']

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.