Skip to main content
Chapter 3 of 7
NCERT Solutions

Data Handling using Pandas - II

CBSE · Class 12 · Informatics Practices

NCERT Solutions for Data Handling using Pandas - II — CBSE Class 12 Informatics Practices.

93 questions86 flashcards5 concepts

Interactive on Super Tutor

Studying Data Handling using Pandas - II? Get the full interactive chapter.

Quizzes, flashcards, AI doubt-solver and a step-by-step study plan — built for ncert solutions and more.

1,000+ Class 12 students started this chapter today

28 Questions Solved · 1 Section

14 worked solutions below. Unlock all 28 free in Super Tutor

Exercise

1Write the statement to install the python connector to connect MySQL i.e. pymysql.Show solution
The statement to install the MySQL connector pymysql is:

```bash
pip install pymysql
```

Not sure why a step works? check your working in Super Tutor

2Explain the difference between pivot() and pivot_table() function?Show solution
pivot() is used to reshape a DataFrame when the entries for the specified index and columns are unique. It rearranges data from rows into a new table.

pivot_table() works like pivot(), but it can handle duplicate entries by applying an aggregate function such as mean, sum, max, or min. The default aggregate function is mean.

So, the main difference is:
- pivot() does not work with duplicate values for the chosen index/columns.
- pivot_table() can reshape data even when duplicates are present, by aggregating them.

Not sure why a step works? check your working in Super Tutor

3What is sqlalchemy?Show solution
sqlalchemy is a library used to interact with the MySQL database by providing the required credentials. It also provides the `create_engine()` function to establish the connection.

Not sure why a step works? check your working in Super Tutor

4Can you sort a DataFrame with respect to multiple columns?Show solution
Yes, a DataFrame can be sorted with respect to multiple columns. In `sort_values()`, we pass a list of column names in the `by` parameter.

For example, if marks in Science are the same, then sorting can be done using Hindi as the next column:

```python
dfUT3 = df[df.UT == 3]
print(dfUT3.sort_values(by=['Science', 'Hindi']))
```

Here, the data is first sorted by Science and then by Hindi.

Not sure why a step works? check your working in Super Tutor

5What are missing values? What are the strategies to handle them?Show solution
A missing value is a value that is not present in a DataFrame. It is denoted by NaN.

The two main strategies to handle missing values are:
1. Drop the object (row) having missing values.
2. Fill/estimate the missing value using an appropriate value, such as 0, 1, previous value, next value, average, minimum, or maximum.

Not sure why a step works? check your working in Super Tutor

6Define the following terms: Median, Standard Deviation and variance.Show solution
- Median: the middle value of the data after arranging it in order. If there are an even number of values, it is the average of the two middle values.
- Standard Deviation: the measure of how much the values vary from the mean; it is the square root of variance.
- Variance: the average of squared differences from the mean.

Not sure why a step works? check your working in Super Tutor

7What do you understand by the term MODE? Name the function which is used to calculate it.Show solution
Mode is the value that appears the most number of times in a dataset. The function used to calculate it in Pandas is `mode()`.

Not sure why a step works? check your working in Super Tutor

8Write the purpose of Data aggregation.Show solution
The purpose of data aggregation is to transform a dataset and produce a single numeric value from an array. It helps summarize data using functions like max(), min(), sum(), count(), std(), and var().

Not sure why a step works? check your working in Super Tutor

9Explain the concept of GROUP BY with help on an example.Show solution
GROUP BY is used to split data into groups based on some criteria, then apply a function to each group, and combine the results.

Example: if we group the marks DataFrame by Name, we can find the first entry, size, or sum for each student.

```python
g1 = df.groupby('Name')
print(g1.first())
print(g1.size())
```

This creates separate groups for Raman, Zuhaire, Ashravy and Mishti, and then operations can be performed group-wise.

Not sure why a step works? check your working in Super Tutor

10Write the steps required to read data from a MySQL database to a DataFrame.Show solution
The steps to read data from a MySQL database to a DataFrame are:

1. Install and import the required libraries, such as `pymysql` and `sqlalchemy`.
2. Create a connection engine using `create_engine()`.
3. Use one of the Pandas functions to read the table/query, such as:
- `pd.read_sql_query(query, engine)`
- `pd.read_sql_table(table_name, engine)`
- `pd.read_sql(sql, engine)`
4. Store the result in a DataFrame.

Example:
```python
engine = create_engine('mysql+pymysql://root:password@localhost:3306/database_name')
df = pd.read_sql_query('SELECT * FROM INVENTORY', engine)
```

Not sure why a step works? check your working in Super Tutor

11Explain the importance of reshaping of data with an example.Show solution
Reshaping data means changing the structure of a DataFrame so that it becomes suitable for analysis. Pandas provides pivot() and pivot_table() for this purpose.

Example: the sales data of stores can be reshaped so that Store becomes the index and Year becomes the columns. Then sales values are easier to compare across years.

This is important because reshaping can make data more readable, organized, and easier to analyze.

Not sure why a step works? check your working in Super Tutor

12Why estimation is an important concept in data analysis?Show solution
Estimation is important in data analysis because missing values represent a loss of information. If we replace them using a suitable estimate such as 0, previous value, next value, or average, we can still perform analysis and get a good approximation of the actual results. Without estimation, some data may have to be dropped, which reduces the size of the dataset.

Not sure why a step works? check your working in Super Tutor

13Assuming the given table: Product. Write the python code for the following:Show solution
The required task is to write Python code for the given Product table and related operations. The table can be stored as a DataFrame using a dictionary and `pd.DataFrame()`.

For example:
```python
import pandas as pd

data = {
'Item': ['TV', 'TV', 'TV', 'AC'],
'Company': ['LG', 'VIDEOCON', 'LG', 'SONY'],
'Rupees': [12000, 10000, 15000, 14000],
'USD': [700, 650, 800, 750]
}

df = pd.DataFrame(data)
```
This creates the DataFrame for the given table.

Not sure why a step works? check your working in Super Tutor

13(a)To create the data frame for the above table.Show solution
To create the DataFrame for the given Product table:

```python
import pandas as pd

data = {
'Item': ['TV', 'TV', 'TV', 'AC'],
'Company': ['LG', 'VIDEOCON', 'LG', 'SONY'],
'Rupees': [12000, 10000, 15000, 14000],
'USD': [700, 650, 800, 750]
}

df = pd.DataFrame(data)
print(df)
```

Not sure why a step works? check your working in Super Tutor

13(b)To add the new rows in the data frame.
13(c)To display the maximum price of LG TV.
13(d)To display the Sum of all products.
13(e)To display the median of the USD of Sony products.
13(f)To sort the data according to the Rupees and transfer the data to MySQL.
13(g)To transfer the new dataframe into the MySQL with new values.
14Write the python statement for the following question on the basis of given dataset:
14(a)To create the above DataFrame.
14(b)To print the Degree and maximum marks in each stream.
14(c)To fill the NaN with 76.
14(d)To set the index to Name.
14(e)To display the name and degree wise average marks of each student.
14(f)To count the number of students in MBA.
14(g)To print the mode marks BCA.

14 more solved questions in Data Handling using Pandas - II

Every remaining exercise is solved step by step in Super Tutor, plus practice quizzes and flashcards for this chapter. Free to start.

Stuck on a step?

Ask Super Tutor AI to explain any solution on this page in a simpler way — free, 24x7.

Ask a Doubt Free

Frequently Asked Questions

What are the important topics in Data Handling using Pandas - II for CBSE Class 12 Informatics Practices?
Data Handling using Pandas - II covers several key topics that are frequently asked in CBSE Class 12 board exams. Focus on the core concepts listed on this page and practise related questions to build confidence.
How to score full marks in Data Handling using Pandas - II — CBSE Class 12 Informatics Practices?
Understand the core concepts first, then work through the 93 practice questions available for this chapter. Revise formulas and definitions regularly, and use flashcards for quick recall before the exam.
Where can I get free NCERT Solutions for Data Handling using Pandas - II Class 12 Informatics Practices?
This page has free step-by-step NCERT Solutions for every exercise question in Data Handling using Pandas - II (CBSE Class 12 Informatics Practices) — written the way examiners award marks: given, formula, working, answer.

Sources & Official References

Content is aligned to the official syllabus. Refer to the board website for the latest curriculum.

For serious students

Get the full Data Handling using Pandas - II chapter — for free.

Quizzes, flashcards, AI doubt-solver and a step-by-step study plan for CBSE Class 12 Informatics Practices.