This lesson reveils you a mapping trick for membership binning. Let’s have a look at a simple situation were this can be useful.
Assume you have a Series and a corresponding “mapping table” where each value belongs to a multi-member group, or to no groups at all:
>>> countries = pd.Series([
... 'United States',
... 'Canada',
... 'Mexico',
... 'Belgium',
... 'United Kingdom',
... 'Thailand'
... ])
...
>>> groups = {
... 'North America': ('United States', 'Canada', 'Mexico', 'Greenland'),
... 'Europe': ('France', 'Germany', 'United Kingdom', 'Belgium')
... }
In other words, you need to map countries
to the following result:
0 North America
1 North America
2 North America
3 Europe
4 Europe
5 other
dtype: object
raulfz on May 6, 2021
Thank you for your Tutorial. The accessor methods and groupby iteration are really great tricks.
However, about this mapping trick I don’t really see any benefit over this:
Best,
R.