rodling
rodling

Reputation: 998

missing data in Dataframe

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

Upvotes: 1

Views: 77

Answers (1)

Andy Hayden
Andy Hayden

Reputation: 375435

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

Upvotes: 2

Related Questions