Skip to content
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")brics_count = brics.count['country']Take Notes
Add notes about the concepts you've learned and code cells with code you want to keep.
print(brics)`brics = {'country':['Brazil', 'Russia', 'India', 'China', 'South Africa'], 'population':[200.4, 143.5, 1252, 1357, 52.98]}
for country, population in zip(brics['country'], brics['population']): print(f'The population of {country} is {population} million!')`
import pandas as pd
for country, population in zip(brics['country'], brics['population']):
print(f'The population of {country} is {population} million!')# Assuming 'brics' is a DataFrame with columns 'country' and 'population'
import pandas as pd
# Sample DataFrame for demonstration
for index, row in brics.iterrows():
country = row['country']
population = row['population']
print(f'The population of {country} is {population} million!')import pandas as pd
brics = pd.read_csv("datasets/brics.csv")
for index, row in brics.iterrows():
country = row['country']
population = row['population']
print(f'The population of {country} is {population} million!')Find in the hidden cell below some exercises to explore the data and practice your skills:
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
bricsDataFrame and prints "The population of {country} is {population} million!". - Create a histogram of the life expectancies for countries in Africa in the
gapminderDataFrame. 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!".
print(True is not False) Cell In[11], line 1
print(True not False)
^
SyntaxError: invalid syntax
The problem was that the original code used incorrect syntax for checking if True is not False. The correct syntax for this comparison is is not instead of not
Use True is not False Run cancelled
fam = [1.73, 1.72, 1.53, 1.89]
for height in fam:
print(height)