1

I am trying to add a column of smaller len into a DataFrame where indexes of smaller item are a subset of a larger item. So if RIMM has data for every single day, but GOOG is missing some day. I want to add RIMM to the matrix with header GOOG

             GOOG
03/12/2012    1
29/11/2012    1
26/11/2012    1

             RIMM    
03/12/2012    1       
30/11/2012    1
29/11/2012    1       
28/11/2012    1
27/11/2012    1
26/11/2012    1       

So it looks something like this

         RIMM    GOOG
03/12/2012    1       1
30/11/2012    1      NaN
29/11/2012    1       1
28/11/2012    1      NaN
27/11/2012    1      NaN
26/11/2012    1       1

I am new to this data type, so any suggestions/tips are welcome

1
  • It's really helpful if you add the output of to_dict(), then we can solve thison our own machines without having to create the dataframes :) Commented Dec 7, 2012 at 17:30

1 Answer 1

2

You are looking for an outer join, here is a simple example:

from pandas import DataFrame
df1 = DataFrame([[1]], columns=['a'])
df2 = DataFrame([[3],[4]], columns=['b'])

In [4]: df1
Out[4]: 
   a
0  1

In [5]: df2
Out[5]: 
   b
0  3
1  4

In [6]: df1.join(df2)
Out[6]: 
   a  b
0  1  3

In [7]: df1.join(df2, how='outer')
Out[7]: 
    a  b
0   1  3
1 NaN  4
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.