Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

This lesson is for members only. Join us and get access to hundreds of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Mapping Trick for Membership Binning

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

Comments & Discussion

Become a Member to join the conversation.