Daniel Bittencourt
Daniel Bittencourt

Reputation: 65

Combine series by date

The following 2 series of stocks in a single excel file:

enter image description here

Can be combined using the date as index?

The result should be like this:

enter image description here

Upvotes: 0

Views: 51

Answers (2)

Mayank Porwal
Mayank Porwal

Reputation: 34046

You need a simple df.merge() here:

df = pd.merge(df1, df2, left_index=True, right_index=True, how='outer')

OR

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

Upvotes: 1

Daniel Bittencourt
Daniel Bittencourt

Reputation: 65

I am trying this:

df3 = pd.concat([df1, df2]).sort_values('Date').reset_index(drop=True)

or

df3 = df1.append(df2).sort_values('Date').reset_index(drop=True)

Upvotes: 1

Related Questions