0

Firstly, I have an empty dataframe df with two columns ['A','B'] and two series s1, s2 which have the same index, What I want to do is to append two series to the dataframe in two steps: At first, it's empty

 A  B

Two series are:

s1:
2019-10-08  0.00496 
2019-10-09  0.00491 
s2:
2019-10-08  0.00116 
2019-10-09  0.00111 

Then I want to append a Series s1, which named '1'

df['A'] = df['A'].append(s1)

My Dataframe now is like

                A    B
2019-10-08  0.00496 NaN
2019-10-09  0.00491 NaN

When I do

df['B'] = df['B'].append(s2)

it says ValueError: cannot reindex from a duplicate axis Anyways to get around it?

The desired result is

 A    B
2019-10-08  0.00496 0.00116
2019-10-09  0.00491 0.00111

It has to assign by indexes with the same appending operations, because s1, s2 indexes might not be exactly the same, and there is no guarantee which appending operation comes first

Bubblethan
  • 379
  • 3
  • 11

1 Answers1

0

You should use an outer join :

df = s1.to_frame(name = 'A').join(s2.to_frame(name='B'), how='outer') 

See comment on this post

Luis Blanche
  • 557
  • 9
  • 18