World Unicorns
2019
USA obviously is
ahead with 172 unicorns. China comes second with 89 unicorns. UK has
17, with India a close behind UK with 16 unicorns.
South Korea and
Germany are next with 8 each. 9 countries have between 2 to 4
unicorns. 11 countries have at least 1 unicorn. In all 26 countries
have unicorns.
How I did it?
World unicorns 2019 |
For mapping
unicorns on the world map; I started with downloading the excel file
from CB Insights.
The first
challenge to me was the valuation was in currency format which was
read as a string in pandas. By writing a function the valuation was
converted into a number.
Then built-in
group by function was used to group and aggregate on count of
unicorns by country.
Now I did not
have country codes in my data frame. The country codes were needed
later to map it using pygal library. So, I downloaded country codes
file from pygal. Later I mapped it and had my original data frame
have country codes in an additional column. However, the mapping did
not recognize South Korea. Its official name is different. So, I had
to correct it.
Then the
countries were put in five buckets as per the count of unicorns in a
country.
The final
challenge was to convert these five data frames into dictionaries. It
was repeatedly giving type error. So, I had to go back to pandas and
dictionaries and read again about sub setting pandas and converting
to dictionaries. Finally, with a lot of tries I could convert five
data frames in to five dictionaries.
These five
dictionaries were used with pygal to plot the words map.