Challenge 1: Mapping Countries to Continents (Trivial)
Explore how to use Pandas' map function to convert country names into continent names within a dataset. Learn to apply mapping for efficient data transformation and create dictionaries linking artists to continents.
We'll cover the following...
Problem definition
Your music analyst would like to know the continent of origin of each band. Can you help them with that?
Expected output
A python dict mapping each band to its continent of origin
Example: {'Cairokee': 'Africa', 'The Beatles': 'Europe'}
The country-to-continent mapping is provided in the challenge as a dict, for example:
{'Egypt': 'Africa', ...}
Challenge
Solution
Solution explanation
Since you are using the country column to convert to the continents, the first step is to use the .map() function on the country column.
This would look like the following: df['country'].map(<function>).
The longer form of the solution would be df['country'].map(lambda x: continents[x]). In this case, x is the value of the country in every row in the dataset, and your function is to get thecontinent based on that.
That solution would be acceptable, but you can simply use df['country'].map(continents).
The last step is just a formatting issue. You can set the index to artist so that when you use the to_dict() function, it will generate a dict mapping the artist to their corresponding continent.