0
0
Pandasdata~30 mins

Bar plots in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Bar plots
📖 Scenario: You work in a small bakery. You want to see how many cakes of each type you sold last week. This will help you understand which cakes are popular.
🎯 Goal: Create a bar plot to show the number of cakes sold for each cake type.
📋 What You'll Learn
Create a pandas DataFrame with cake types and their sales.
Set a variable for the plot title.
Use pandas to create a bar plot of the sales.
Display the bar plot with the correct title.
💡 Why This Matters
🌍 Real World
Bar plots are used in business to quickly see which products sell best or which categories have the most data.
💼 Career
Data analysts and scientists use bar plots to visualize and communicate data insights clearly to teams and managers.
Progress0 / 4 steps
1
Create the sales data
Create a pandas DataFrame called sales_data with two columns: 'Cake' and 'Sold'. The 'Cake' column should have these exact values: 'Chocolate', 'Vanilla', 'Strawberry', 'Lemon'. The 'Sold' column should have these exact values: 50, 40, 30, 20.
Pandas
Need a hint?

Use pd.DataFrame with a dictionary where keys are column names and values are lists of data.

2
Set the plot title
Create a variable called plot_title and set it to the string 'Cake Sales Last Week'.
Pandas
Need a hint?

Just assign the string to the variable plot_title.

3
Create the bar plot
Use the plot method on sales_data to create a bar plot. Use x='Cake' and y='Sold' as arguments. Save the plot object in a variable called bar_plot.
Pandas
Need a hint?

Use sales_data.plot(x='Cake', y='Sold', kind='bar') and assign it to bar_plot.

4
Show the bar plot with title
Set the title of bar_plot to plot_title using set_title(). Then import matplotlib.pyplot as plt and call plt.show() to display the plot.
Pandas
Need a hint?

Use bar_plot.set_title(plot_title) and then plt.show() to display the plot.