Skip to content
Activities · Activity 4.1
Q.

Create the MelaSale.csv using Python Pandas containing data as shown in Table 4.6.

Table 4.6 -- Day-wise mela sales data (in Rs):

Week 1Week 2Week 3
500040004000
590030005800
650050003500
350055002500
400030003000
530043005300
790059006000
Yanam CbseNCERTSubjective· 3mImportance★★★★★
5% · 2/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 →

This task asks you to create a CSV file (MelaSale.csv) from scratch using Python Pandas, with the exact day-wise mela sales data given in Table 4.6 — three weeks of sales figures across seven days.

The core idea here is DataFrame construction from raw data. You are not reading an existing file; you are writing one. The natural tool is pandas.DataFrame to hold the data in memory, then to_csv() to persist it. The shape of the question is a code / query task — you must produce a complete, runnable Python script that creates the CSV exactly as specified.

First, understand the structure. Table 4.6 shows three columns (Week 1, Week 2, Week 3) and seven rows — one for each day of the week. The sales figures are given in the order: row 1: 5000, 4000, 4000; row 2: 5900, 3000, 5800; and so on. There is no explicit day-name column in the table, but a well-formed CSV should include a day index or day names for clarity. The question says "day-wise" — I will add a Day column with values Monday through Sunday, as that is the natural interpretation and makes the data usable.

import pandas as pd

# Data from Table 4.6: each inner list is one day's sales for Week 1, Week 2, Week 3
data = {
    'Day': ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
    'Week 1': [5000, 5900, 6500, 3500, 4000, 5300, 7900],
    'Week 2': [4000, 3000, 5000, 5500, 3000, 4300, 5900],
    'Week 3': [4000, 5800, 3500, 2500, 3000, 5300, 6000]
}

df = pd.DataFrame(data)

# Write to CSV without the default index column
df.to_csv('MelaSale.csv', index=False)

print("MelaSale.csv created successfully.")
print(df)

Key lines explained:

  • pd.DataFrame(data): This constructs a DataFrame from a dictionary. Each key becomes a column name, and the list of values becomes that column's data. The order of keys determines column order in the DataFrame.
  • df.to_csv('MelaSale.csv', index=False): The index=False parameter is critical — without it, Pandas would write an extra unnamed column of row numbers (0, 1, 2…) into the CSV, which is not part of the given table. This keeps the output clean and matching the source. …

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.