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 1 | Week 2 | Week 3 |
|---|---|---|
| 5000 | 4000 | 4000 |
| 5900 | 3000 | 5800 |
| 6500 | 5000 | 3500 |
| 3500 | 5500 | 2500 |
| 4000 | 3000 | 3000 |
| 5300 | 4300 | 5300 |
| 7900 | 5900 | 6000 |
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 > 18orcity == "Mumbai". - Which columns? You specify which attributes you want to see — for example, only
nameandscore, 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?"
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:
- Filters rows to those where
Streamis "Commerce" ANDCityis "Delhi" ANDPercentageis greater than 75. - Selects only the
NameandPercentagecolumns.
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.