Skip to content
Programs · Program 4-6
Q.

(Program 4-6) Write a Python script to display a Bar plot for the "MelaSales.csv" file with column Day on x axis, titled "Mela Sales Report" and y axis labelled "Sales in Rs".

Table 4.7 -- day-wise sales data along with Day's names:

Week 1Week 2Week 3Day
500040004000Monday
590030005800Tuesday
650050003500Wednesday
350055002500Thursday
400030003000Friday
530043005300Saturday
790059006000Sunday
Punjab PsebTextbookSubjective· 3mImportance★★★★★est
20% · 9/44 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

A grouped bar chart -- one call plots all three weeks as side-by-side bars per day.

import pandas as pd
df= pd.read_csv('MelaSales.csv')
import matplotlib.pyplot as plt
df.plot(kind='bar',x='Day',title='Mela Sales Report')
plt.ylabel('Sales in Rs')
plt.show()

df.plot(kind='bar', x='Day', ...) automatically draws one bar PER numeric column per day (a grouped bar chart) -- there's no need to sum the weeks into a single total.

Step by step

  1. pd.read_csv('MelaSales.csv') loads Table 4.7, which (unlike Table 4.6) has a fourth column, Day, holding the day names.
  2. df.plot(kind='bar', x='Day', ...) tells pandas to use the Day column as the category axis instead of the default row-number index -- every OTHER numeric …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.