0
0
Data Analysis Pythondata~30 mins

Bar charts in Data Analysis Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Bar charts
📖 Scenario: You work at a small bakery. You want to show how many cakes of each type you sold last week. A bar chart is a great way to show this information clearly.
🎯 Goal: Create a bar chart that shows the number of cakes sold for each cake type.
📋 What You'll Learn
Create a dictionary with cake types and their sales numbers
Create a list of cake types from the dictionary keys
Create a list of sales numbers from the dictionary values
Use matplotlib to create a bar chart with cake types on the x-axis and sales numbers on the y-axis
Add labels for the x-axis, y-axis, and a title to the chart
Display the bar chart
💡 Why This Matters
🌍 Real World
Bar charts are used in business to show sales, in schools to show test scores, and in many places to compare amounts clearly.
💼 Career
Data analysts and scientists use bar charts to communicate data insights visually to teams and decision makers.
Progress0 / 4 steps
1
Create the sales data dictionary
Create a dictionary called cake_sales with these exact entries: 'Chocolate': 30, 'Vanilla': 45, 'Strawberry': 25, 'Lemon': 20.
Data Analysis Python
Hint

Use curly braces {} to create a dictionary. Separate keys and values with a colon : and items with commas.

2
Prepare lists for the bar chart
Create a list called cake_types containing the keys of cake_sales. Create another list called sales_numbers containing the values of cake_sales.
Data Analysis Python
Hint

Use list() with cake_sales.keys() and cake_sales.values() to get lists.

3
Create the bar chart
Import matplotlib.pyplot as plt. Use plt.bar() with cake_types and sales_numbers to create the bar chart. Add x-axis label 'Cake Types', y-axis label 'Number Sold', and title 'Cake Sales Last Week' using plt.xlabel(), plt.ylabel(), and plt.title().
Data Analysis Python
Hint

Use plt.bar(x, y) to create bars. Use plt.xlabel(), plt.ylabel(), and plt.title() to add labels and title.

4
Display the bar chart
Use plt.show() to display the bar chart.
Data Analysis Python
Hint

Call plt.show() to open a window with the bar chart.