Data Handling using Pandas Class 12 NCERT Solution

Share with others

Data Handling using Pandas Class 12

Data Handling using Pandas Class 12
Data Handling using Pandas Class 12
Data Handling using Pandas Class 12

SUMMARY :

NumPy, Pandas and Matplotlib are Python libraries for scientific and analytical use. 

pip install pandas is the command to install Pandas library.

A data structure is a collection of data values and the operations that can be applied to that 
data. It enables efficient storage, retrieval and modification to the data.
 
Two main data structures in Pandas library are Series and DataFrame. To use these 
data structures, we first need to import the Pandas library.

A Series is a one-dimensional array containing a sequence of values. Each value has a data label 
associated with it also called its index. 

The two common ways of accessing the elements of a series are Indexing and Slicing.

There are two types of indexes: positional index and labelled index. Positional index takes an 
integer value that corresponds to its position in the series starting from 0, whereas labelled index 
takes any user-defined label as index.

When positional indices are used for slicing, the value at end index position is excluded, i.e., only 
(end - start) number of data values of the series are extracted. However with labelled indexes the
value at the end index label is also included in the output. 

All basic mathematical operations can be performed on Series either by using the 
operator or by using appropriate methods of the Series object. 

While performing mathematical operations index matching is implemented and if no matching 
indexes are found during alignment, Pandas returns NaN so that the operation does not fail.

A DataFrame is a two-dimensional labeled data structure like a spreadsheet. It contains rows 
and columns and therefore has both a row and column index.

When using a dictionary to create a DataFrame, keys of the Dictionary become the column labels 
of the DataFrame. A DataFrame can be thought of as a dictionary of lists/ Series (all Series/columns 
sharing the same index label for a row).

Data can be loaded in a DataFrame from a file on the disk by using Pandas read_csv function.

Data in a DataFrame can be written to a text file on disk by using the pandas.DataFrame.to_
csv() function.

DataFrame.T gives the transpose of a DataFrame. 

Pandas haves a number of methods that support label based indexing but every label asked for 
must be in the index, or a KeyError will be raised. 

DataFrame.loc[ ] is used for label based indexing of rows in DataFrames. 

Pandas.DataFrame.append() method is used to merge two DataFrames. 

Pandas supports non-unique index values. Only 
if a particular operation that does not support 
duplicate index values is attempted, an exception is raised at that time.

The basic difference between Pandas Series and NumPy ndarray is that operations between Series 
automatically align the data based on labels. Thus, we can write computations without considering 
whether all Series involved have the same label or not whereas in case of ndarrays it raises an error.

Data Handling using Pandas Class 12

Data Handling using Pandas Class 12

Data Handling using Pandas Class 12
Data Handling using Pandas Class 12

Q1. What is a Series and how is it different from a 1-D array, a list and a dictionary?


Q2. What is a DataFrame and how is it different from a 2-D array?

Q3. How are DataFrames related to Series?

Q4. What do you understand by the size of (i) a Series, (ii) a DataFrame?

Data Handling using Pandas Class 12 NCERT Solutions

Data Handling using Pandas Class 12
Data Handling using Pandas Class 12

Q5. Create the following Series and do the specified operations:


a) EngAlph, having 26 elements with the alphabets as values and default index values.


b) Vowels, having 5 elements with index labels ‘a’, ‘e’, ‘i’, ‘o’ and ‘u’ and all the five values set to zero. Check if it is an empty series.


c) Friends, from a dictionary having roll numbers of five of your friends as data and their first name as keys.


d) MTseries, an empty Series. Check if it is an empty series.


e) MonthDays, from a numpy array having the number of days in the 12 months of a year. The labels should be the month numbers from 1 to 12.




Data Handling using Pandas Class 12 NCERT Solutions

Q6. Using the Series created in Question 5, write commands for the following:


a) Set all the values of Vowels to 10 and display the Series.


Data Handling using Pandas Class 12


b) Divide all values of Vowels by 2 and display the Series.




c) Create another series Vowels1 having 5 elements with index labels ‘a’, ‘e’, ‘i’, ‘o’ and ‘u’ having values [2,5,6,3,8] respectively.




d) Add Vowels and Vowels1 and assign the result to Vowels3.





e) Subtract, Multiply and Divide Vowels by Vowels1.




f) Alter the labels of Vowels1 to [‘A’, ‘E’, ‘I’, ‘O’, ‘U’].



Data Handling using Pandas Class 12 NCERT Solutions

Data Handling using Pandas Class 12
Data Handling using Pandas Class 12

Q7. Using the Series created in Question 5, write commands for the following :

a) Find the dimensions, size and values of the Series EngAlph, Vowels, Friends, MTseries, MonthDays.



Data Handling using Pandas Class 12

b) Rename the Series MTseries as SeriesEmpty.




c) Name the index of the Series MonthDays as monthno and that of Series Friends as Fname.

d) Display the 3rd and 2nd value of the Series Friends, in that order.

e) Display the alphabets ‘e’ to ‘p’ from the Series EngAlph.



f) Display the first 10 values in the Series EngAlph.



h) Display the MTseries.



Data Handling using Pandas Class 12 NCERT Solutions

8. Using the Series created in Question 5, write commands for the following:

a) Display the names of the months 3 through 7 from the Series MonthDays.


b) Display the Series MonthDays in reverse order.

Data Handling using Pandas Class 12 NCERT Solutions

Q9. Create the following DataFrame Sales containing year-wise sales figures for five salespersons in INR. Use the years as column labels, and salesperson names as row labels.

2014201520162017
Madhu100.5120002000050000
Kusum150.8180005000060000
Kinshuk200.9220007000070000
Ankit30000300001000080000
Shruti400004500012500090000


Q10. Use the DataFrame created in Question 9 above to do the following:

a) Display the row labels of Sales.



b) Display the column labels of Sales.



c) Display the data types of each column of Sales.

d) Display the dimensions, shape, size and values of Sales.



e) Display the last two rows of Sales.



f) Display the first two columns of Sales.



g) Create a dictionary using the following data. Use this dictionary to create a DataFrame Sales2.

2018
Madhu160000
Kusum110000
Kinshuk500000
Ankit340000
Shruti900000

h) Check if Sales2 is empty or it contains data.

Data Handling using Pandas Class 12 NCERT Solutions

Q11. Use the DataFrame created in Question 9 above to do the following:

a) Append the DataFrame Sales2 to the DataFrame Sales.

b) Change the DataFrame Sales such that it becomes its transpose.

c) Display the sales made by all sales persons in the year 2017.

d) Display the sales made by Madhu and Ankit in the year 2017 and 2018.

e) Display the sales made by Shruti 2016.

Data Handling using Pandas Class 12 NCERT Solutions

f) Add data to Sales for salesman Sumeet where the sales made are [196.2, 37800, 52000, 78438, 38852] in the years [2014, 2015, 2016, 2017, 2018] respectively

g) Delete the data for the year 2014 from the DataFrame Sales.

h) Delete the data for sales man Kinshuk from the DataFrame Sales.

 

i) Change the name of the salesperson Ankit to Vivaan and Madhu to Shailesh.

j) Update the sale made by Shailesh in 2018 to 100000.

k) Write the values of DataFrame Sales to a comma separated file SalesFigures.csv on the disk. Do not write the row labels and column labels

l) Read the data in the file SalesFigures.csv into a DataFrame SalesRetrieved and Display it. Now update the row labels and column labels of SalesRetrieved to be the same as that of Sales.

Data Handling using Pandas Class 12 NCERT Solutions


Data Handling using Pandas Class 12 NCERT Solutions

Disclaimer : I tried to give you the correct ” Data Handling using Pandas Class 12 NCERT Solutions , but if you feel that there is/are mistakes in ” Data Handling using Pandas Class 12 NCERT Solutions ” given above, you can directly contact me at csiplearninghub@gmail.com. Book and Study material available on CBSE official website are used as a reference to create above “ Data Handling using Pandas Class 12 NCERT Solutions “.


Data Handling using Pandas Class 12 NCERT Solutions

Important Links

100 Practice Questions on Python Fundamentals

120+ MySQL Practice Questions

90+ Practice Questions on List

50+ Output based Practice Questions

100 Practice Questions on String

70 Practice Questions on Loops

120 Practice Questions of Computer Network in Python

70 Practice Questions on if-else

40 Practice Questions on Data Structure

Computer Science Syllabus 2021-2022.

Informatics Practices Syllabus 2021-2022

Class 12 Computer Science Chapter wise MCQ

Data Handling using Pandas Class 12 NCERT Solutions

Data Handling using Pandas Class 12 NCERT Solutions

Data Handling using Pandas Class 12 NCERT Solutions


Share with others

Leave a Reply

%d bloggers like this: