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
Puducherry 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 →

Concept understanding — DataFrame Querying

DataFrame Querying: Finding What You Need in a Table

Think of a DataFrame as a digital spreadsheet — rows of records (like each customer, each student, each transaction) and columns of attributes (name, age, city, purchase amount). Querying is simply the act of asking questions of that table: "Show me only the rows where the city is Delhi" or "Give me all students who scored above 80 in Economics."

You already do this in everyday life. When you open your contacts app and type "R" to see only names starting with R, you are querying. When you filter your email to show only unread messages, you are querying. A DataFrame query is the same idea, but more powerful and precise.

The Precise Meaning

In the context of a DataFrame (a two-dimensional, labelled data structure), querying means selecting a subset of rows and/or columns based on some condition or set of conditions. The original DataFrame remains unchanged; you get a new, smaller view of the data that answers your specific question.

The key parts of any query are:

  • Which rows? You specify a condition — for example, rows where age > 18 or city == "Mumbai".
  • Which columns? You specify which attributes you want to see — for example, only name and score, or all columns.

A query can combine multiple conditions using logical operators like AND, OR, and NOT. For instance: "Show me all rows where the city is Bangalore AND the purchase amount is greater than 5000."

Why It Matters

DataFrame querying is the foundation of data analysis. Without it, you are stuck looking at the entire table — thousands or millions of rows — and trying to spot patterns by eye. That is impossible for any real-world dataset.

Querying lets you:

  • Find specific records — "Which customers have not paid their bill?"
  • Compare groups — "How do sales in the North zone differ from the South zone?"
  • Prepare data for further analysis — "Extract only the records from the last financial year."
  • Check for errors — "Are there any rows where the age is negative?"
Important

A query does not change the original data. It creates a new, filtered view. This is crucial: you can run many different queries on the same DataFrame without ever altering the source. The original table stays safe.

A Simple Example in Words

Imagine a DataFrame called Students with columns: Name, Stream, Percentage, City.

A query like "Show me all Commerce students" would return a new table containing only those rows where the Stream column has the value "Commerce". All columns — Name, Stream, Percentage, City — would still appear, but only for Commerce students.

A more specific query: "Show me the names and percentages of Commerce students from Delhi who scored above 75." This query:

  1. Filters rows to those where Stream is "Commerce" AND City is "Delhi" AND Percentage is greater than 75.
  2. Selects only the Name and Percentage columns.

The result is a small, focused table — exactly the information you need, nothing more. …

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.