| A | Assignment |
Please complete Exercises write your solutions in a single Python script named unit08_assigment.py.
Save all scripts in the same unit08_assigment folder, compress the folder into a .zip file, and upload it to ILIAS.
For more information, please visit the following link:
https://geomoer.github.io/moer-base-python/unit00/unit00-04_submission_guidelines.html
Make sure your code is clearly structured and includes comments where helpful.
Dataset World Bank – Total Population by Country and Year
import pandas as pd
import matplotlib.pyplot as plt
url = "https://raw.githubusercontent.com/datasets/population/master/data/population.csv"
df = pd.read_csv(url)
Analyze and compare population development of selected countries and visualize the results.
Task 1 – Data Exploration
- Print the column names.
- Display the first 5 rows of the dataset.
- Determine:
- the minimum year in the dataset
- the maximum year in the dataset
Task 2 - Line Plot: Population Over Time
- Create one line plot showing population development over time for the following five African countries:
- Nigeria
- Egypt
- Ethiopia
- South Africa
- Kenya
- Each country must have its own line in the plot.
- Explicitly define the x-axis so that it starts at the minimum year and ends at the maximum year in the dataset.
You can use the functionplt.xlim()for this. - Add:
- a descriptive title
- an x-axis label
- a y-axis label
- a legend
Task 3 - Population Comparison for One Year
- Select the year 2020.
- Filter the data so that it contains only the following five European countries:
- Germany
- France
- United Kingdom
- Italy
- Spain
Hint: There is a pandas function that allows you to check whether values are contained in a list (2020).
- Create:
- a bar chart comparing the population sizes of these countries in 2020
- a pie chart with percentages showing each country’s share of the total population
Hint: Make sure that both charts are based on the same filtered dataset (year 2020 and the selected countries).
Titanic Data Visualization – Python Homework
Dataset (used for all tasks)
import pandas as pd
import matplotlib.pyplot as plt
url = "https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv"
df = pd.read_csv(url)
Task 4 – Survivors vs. Non-Survivors
- Access the column
Survived. - Count survivors and non-survivors using
value_counts(). - Create:
- a bar chart
- a pie chart with percentages
- Add titles and axis labels.
Task 5 – Gender Distribution
- Use the column
Sex. - Count male and female passengers.
- Create a pie chart with percentages.
Task 6 – Passenger Class Distribution
- Use the column
Pclass. - Count passengers per class.
- Create a bar chart or pie chart.
Bonus Task – Multiple Plots in One Figure
Create a figure with multiple subplots (e.g. 2x2) including:
- Survivors
- Gender distribution
- Passenger class distribution
Each subplot must have its own title and one global figure title.