0
0
Pandasdata~30 mins

Line plots with plot() in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Line plots with plot()
📖 Scenario: You work as a data analyst for a small bakery. You have daily sales data for different types of bread over a week. You want to visualize how sales changed each day to understand trends.
🎯 Goal: Create a line plot using pandas plot() to show daily sales of different bread types over a week.
📋 What You'll Learn
Create a pandas DataFrame with daily sales data for three bread types.
Set a variable for the days of the week.
Use the DataFrame's plot() method to create a line plot.
Display the plot using plt.show().
💡 Why This Matters
🌍 Real World
Line plots help visualize trends over time, such as daily sales, temperature changes, or stock prices.
💼 Career
Data analysts and scientists use line plots to communicate patterns and insights clearly to teams and decision makers.
Progress0 / 4 steps
1
Create the sales data DataFrame
Import pandas as pd and create a DataFrame called sales_data with these exact columns and values: 'Sourdough' with [20, 22, 19, 24, 30, 28, 25], 'Baguette' with [15, 18, 14, 20, 22, 21, 19], and 'Rye' with [10, 12, 11, 13, 15, 14, 13].
Pandas
Need a hint?

Use pd.DataFrame() with a dictionary where keys are bread types and values are lists of sales numbers.

2
Add days of the week as index
Create a list called days with these exact values: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']. Then set this list as the index of the sales_data DataFrame.
Pandas
Need a hint?

Assign the list days to sales_data.index to label rows by day.

3
Create the line plot
Import matplotlib.pyplot as plt. Use the plot() method on sales_data to create a line plot showing sales trends for each bread type.
Pandas
Need a hint?

Call sales_data.plot() to create the line plot. Make sure to import matplotlib.pyplot as plt.

4
Display the plot
Use plt.show() to display the line plot you created.
Pandas
Need a hint?

Call plt.show() after plotting to see the graph window.