Skip to content
1 hidden cell
Intermediate Python
Intermediate Python
Run the hidden code cell below to import the data used in this course.
1 hidden cell
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
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!".
DataFrameas
events_per_city
variable
SELECT v.venuecity, COUNT(e.eventid) AS event_count
FROM event e
JOIN venue v ON e.venueid = v.venueid
GROUP BY v.venuecity
ORDER BY event_count DESC
LIMIT 20;
import plotly.express as px
events_per_city = pd.DataFrame({
'venuecity': ['New York City', 'Los Angeles', 'Las Vegas', 'Chicago', 'San Francisco', 'Washington', 'Houston', 'Detroit', 'Boston', 'Baltimore', 'Denver', 'Seattle', 'Minneapolis', 'St. Louis', 'Toronto'],
'event_count': [2647, 312, 300, 209, 194, 164, 155, 152, 144, 142, 136, 136, 131, 127, 120]
})
fig = px.bar(events_per_city, x='venuecity', y='event_count', title='Top 20 Cities by Number of Events', labels={'venuecity': 'City', 'event_count': 'Number of Events'})
fig.show()