Implement ordered merge function · Issue #813 · pandas-dev/pandas (original) (raw)
Navigation Menu
- GitHub Copilot Write better code with AI
- GitHub Models New Manage and compare prompts
- GitHub Advanced Security Find and fix vulnerabilities
- Actions Automate any workflow
- Codespaces Instant dev environments
- Issues Plan and track work
- Code Review Manage code changes
- Discussions Collaborate outside of code
- Code Search Find more, search less
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Description
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