Implement ordered merge function · Issue #813 · pandas-dev/pandas (original) (raw)

Skip to content

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

@wesm

Description

@wesm

Something like this:

In [87]: df
Out[87]: 
       Date    Px
0  1/1/2001  21.2
1  1/2/2001  22.0
2  1/3/2001  25.0

In [88]: df2
Out[88]: 
   Individual      Date  Exercises
0           1  1/1/2001         10
1           2  1/3/2001          5

In [89]: f = lambda x: merge(x, df, how='outer')

In [90]: concat([f(y) for x, y in df2.groupby('Individual')], ignore_index=False)
Out[90]: 
   Individual      Date  Exercises    Px
0           1  1/1/2001         10  21.2
1         NaN  1/2/2001        NaN  22.0
2         NaN  1/3/2001        NaN  25.0
0         NaN  1/1/2001        NaN  21.2
1         NaN  1/2/2001        NaN  22.0
2           2  1/3/2001          5  25.0

but should be able to propagate certain fields and allow others to be NA