Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ordered merge function #813

Closed
wesm opened this issue Feb 22, 2012 · 1 comment
Closed

Implement ordered merge function #813

wesm opened this issue Feb 22, 2012 · 1 comment
Milestone

Comments

@wesm
Copy link
Member

wesm commented Feb 22, 2012

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

@wesm wesm closed this as completed in 3fdc6d9 May 15, 2012
@wesm
Copy link
Member Author

wesm commented May 15, 2012

outcome:

In [9]: ordered_merge(df, df2, on='Date', right_by='Individual', fill_method='ffill')
Out[9]: 
       Date    Px  Individual  Exercises
0  1/1/2001  21.2           1         10
1  1/2/2001  22.0           1         10
2  1/3/2001  25.0           1         10
3  1/1/2001  21.2           2        NaN
4  1/2/2001  22.0           2        NaN
5  1/3/2001  25.0           2          5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant