Skip to content
    final_project@therka
    .gitignore
    data.csv
    main.py
    Packager files
    poetry.lock
    pyproject.toml
    Config files
    .replit
    replit.nix
    import csv
    import matplotlib.pyplot as plt


    def get_population_data(filename):
    """
    Read file, extract data for continent, year and population

    Present data like this {
    'Africa': {year:[1990, 2000, 2010], population: [100, 200, 300]}
    'Europe': {year:[1990, 2000, 2010], population: [100, 200, 300]}
    }
    """

    output= {}

    #open the file
    with open(filename, 'r') as csvfile:
    reader = csv.DictReader(csvfile)
    for row in reader:
    continent = row['continent']
    year = int(row['year'])
    population = int(row['population'])

    if continent not in output:
    output[continent] = {'population':[],'year':[]}

    output[continent]['population'].append(population)
    output[continent]['year'].append(year)

    return output



    def generate_population_graph(population_data):
    """
    Generate population plot from the population data above,creating one line per continent and the world
    """

    for continent in population_data:
    years = population_data[continent]['year']
    population = population_data[continent]['population']
    plt.plot(years, population, label = continent, linestyle = '--', marker = 'D', ms= 2.5, alpha = 0.8)

    plt.legend()
    plt.title('Internet Population per Continent')
    plt.xlabel('Year')
    plt.ylabel('Number of Internet users (in billions)')
    plt.tight_layout()
    plt.grid(True)
    (plt.grid(axis='y'))
    plt.show()


    #specify document name
    filename ='data.csv'

    #get population data
    population_per_continent = get_population_data(filename)

    # Plot population data on graph
    generate_population_graph(population_per_continent)

    #coded by Theri Reichlin github.com/therikay