Using multiple merge-by columns
The same logic we used to perform one-to-one merges with one merge-by column applies to merges we perform with multiple merge-by columns. Inner, outer, left, and right joins work the same way when you have two or more merge-by columns. We will demonstrate this in this recipe.
Getting ready
We will work with the NLS data in this recipe, specifically weeks worked and college enrollment from 2000 through 2004. Both the weeks worked and college enrollment files contain one row per person, per year.
How to do it...
We will continue this recipe with one-to-one merges, but this time with multiple merge-by columns on each DataFrame. Let's get started:
- Import
pandas
and load the NLS weeks worked and college enrollment data:>>> import pandas as pd >>> nls97weeksworked = pd.read_csv("data/nls97weeksworked.csv") >>> nls97colenr = pd.read_csv("data/nls97colenr.csv")
- Look at some of the NLS...