Intermediate Python
  • AI Chat
  • Code
  • Report
  • Beta
    Spinner

    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.

    MANIPULATING dICTIONARIES

    # Add your code snippets here
    # Definition of countries and capital
    countries = ['spain', 'france', 'germany', 'norway']
    capitals = ['madrid', 'paris', 'berlin', 'oslo']
    
    # Get index of 'germany': ind_ger
    ind_ger = countries.index('germany')
    
    # Use ind_ger to print out capital of Germany
    print(capitals[ind_ger])

    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!".
    Unknown integration
    DataFrameavailable as
    df
    variable
    -- Find the country with the highest life expectancy, based on data from 2015
    SELECT
    	countries_plus.name,
    	populations.life_expectancy
    FROM world.countries_plus
    	INNER JOIN world.populations ON countries_plus.code = populations.country_code
    WHERE
    	populations.year = 2015
    	AND populations.life_expectancy IS NOT NULL
    ORDER BY populations.life_expectancy DESC
    This query is taking long to finish...Consider adding a LIMIT clause or switching to Query mode to preview the result.
    i =1
    
    while i <= 8:
        print(i)
        i +=1