| EX | Exercises |
✨ Simple Visualization Practice Tasks
These tasks are designed to help you practice simple data visualization in Python using Matplotlib. You will use a CSV file as a data source, load it into a DataFrame, and create different plots. The total estimated time for all tasks is about 20 minutes.
🔥 Task 1: Plot a single product line
- Download the provided CSV file (
data.csv) or load it directly read_csv(url) from the URL: https://geomoer.github.io/moer-base-python/assets/tests/unit08/data.csv usingpandas. - Create a line plot that shows the revenue of Product A over the years(X-Axis).
- Add a descriptive title to your plot (e.g., “Revenue of Product A over Time”).
- Label the x-axis as “Year” and the y-axis as “Revenue in USD”.
- Use a solid line style (e.g., linestyle=’-‘) so that the line appears as “—-“.
- Add different markers to your line using marker(see the table on https://geomoer.github.io/moer-base-python/unit08/unit08-04_creating.html.
📘 Task 2: Exploring the Titanic Dataset
In this exercise, you will load the Titanic dataset and perform a basic first exploration using Pandas. This will help you understand the structure of the data before creating diagrams with Matplotlib.
🔹 Load and Inspect the Dataset
- Load the Titanic CSV file into a Pandas DataFrame
import pandas as pd df = pd.read_csv("https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv") - Display the first rows of the dataset
df.head() - Show basic information about the dataset**
- Number of rows and columns
- Column names
- Data types
- Missing values
df.info()
- Generate basic descriptive statistics
df.describe() - Count how many passengers are in each category, for example:
- Number of males and females
- Number of passengers in each passenger class
df['Sex'].value_counts() df['Pclass'].value_counts()
-
Create Basic Visualizations
- A bar chart showing the number of male vs. female passengers
Use the categories from
df['Sex'].value_counts().indexas the x-axis labels. Use the counts fromdf['Sex'].value_counts().valuesas the bar heights.categories = df['Pclass'].value_counts().index - A bar chart showing the number of passengers in each passenger class (Pclass)
Use the categories from
df['Pclass'].value_counts().indexas the x-axis labels. Use the counts fromdf['Pclass'].value_counts().valuesas the bar heights.
- A bar chart showing the number of male vs. female passengers
Use the categories from