Skip to content
New Workbook
Sign up
Intermediate Python

Intermediate Python

Run the hidden code cell below to import the data used in this course.

# Import the course packages
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# Import the two datasets
gapminder = pd.read_csv("datasets/gapminder.csv")
brics = pd.read_csv("datasets/brics.csv")

Take Notes

Add notes about the concepts you've learned and code cells with code you want to keep.

Add your notes here

# Add your code snippets here
# For time related data, a line plot is a fine choice. But for cases when you whant to know the correlations bettwen different data, a sccatter plot is a better choice
  • Use line plot for time related data, to show evolution of data obver time for exemple
  • Use scatter plt for correlation between datas
  • Use histogram if you want to look for a particular distribution of your data
Current Type: Bar
Current X-axis: population
Current Y-axis: area
Current Color: None

Test

Explore Datasets

Use the DataFrames imported in the first cell to explore the data and practice your skills!

  • Create a loop that iterates through the brics DataFrame and prints "The population of {country} is {population} million!".
  • Create a histogram of the life expectancies for countries in Africa in the gapminder DataFrame. Make sure your plot has a title, axis labels, and has an appropriate number of bins.
  • Simulate 10 rolls of two six-sided dice. If the two dice add up to 7 or 11, print "A win!". If the two dice add up to 2, 3, or 12, print "A loss!". If the two dice add up to any other number, print "Roll again!".

Use plt.y (or x) pltyticks[0, 2, ...] to change the intervall value for your axis, you can also add anothe list ot add description to the axis values

plt.yticks([0, 2, ...], [0, '2Millions', ...] )

For a pandas dataframe doing this =>

import pandas as pd ... df['col_name'] # Retrun a panda serie df[['col_name']] # Return a panda dataframe