Solution: Create a Bar Chart Race
See the solution to the bar chart race challenge.
Task 1: Read and display data
We will use pandas to read the country_population.csv
file and display its records to understand the dataset’s structure and content.
C++
import pandas as pd# Read the datasetdf = pd.read_csv('country_population.csv')# Display the first few recordsprint(df)
The above code reads the CSV file country_population.csv
into a pandas DataFrame named df
and then displays all the records.
Task 2: Create a color dictionary
Here is a dictionary mapping country names to colors, as follows:
colors = {'Bangladesh': 'skyblue','Brazil': 'pink','China': 'orange','India': 'blue','Indonesia': 'purple','Nigeria': 'brown','Pakistan': 'green','Russia': 'gray','United States': 'red'}
Color dictionary mapping
This dictionary maps country names to their corresponding colors for visualization.
Task 3: Function for population conversion
The function named population_to_millions(population)
will convert the population values to ...