So I have a column of my dataframe that looks like this:
10 first rows of the column expeditions['first_ascent_country']
0 New Zealand, USA, UK
1 UK
2 France
3 UK, Nepal
4 India
5 W Germany
6 Spain
7 W Germany
8 Japan, Nepal
9 Japan, Nepal
It gives information on which country climbed a mountain first. I want to display those countries in a barplot to show which ones discovered more, but I get this... How do I separate the countries using a comma?
Step by step:
>>> df['peak_ascent_country'].str.split(', ')
0 [New Zealand, USA, UK]
1 [UK]
2 [France]
3 [UK, Nepal]
4 [India]
5 [W Germany]
6 [Spain]
7 [W Germany]
8 [Japan, Nepal]
9 [Japan, Nepal]
Name: peak_ascent_country, dtype: object
>>> df['peak_ascent_country'].str.split(', ').explode().value_counts()
0 New Zealand
0 USA
0 UK
1 UK
2 France
3 UK
3 Nepal
4 India
5 W Germany
6 Spain
7 W Germany
8 Japan
8 Nepal
9 Japan
9 Nepal
Name: peak_ascent_country, dtype: object
>>> df['peak_ascent_country'].str.split(', ').explode().value_counts()
UK 3
Nepal 3
W Germany 2
Japan 2
New Zealand 1
USA 1
France 1
India 1
Spain 1
Name: peak_ascent_country, dtype: int64