CBSE Class 12 Informatics Practices Data Handling using Pandas Assignment Set B

Read and download free pdf of CBSE Class 12 Informatics Practices Data Handling using Pandas Assignment Set B. Get printable school Assignments for Class 12 Informatics Practices. Class 12 students should practise questions and answers given here for Chapter 02 Data Handling using Pandas I Informatics Practices in Class 12 which will help them to strengthen their understanding of all important topics. Students should also download free pdf of Printable Worksheets for Class 12 Informatics Practices prepared as per the latest books and syllabus issued by NCERT, CBSE, KVS and do problems daily to score better marks in tests and examinations

Assignment for Class 12 Informatics Practices Chapter 02 Data Handling using Pandas I

Class 12 Informatics Practices students should refer to the following printable assignment in Pdf for Chapter 02 Data Handling using Pandas I in Class 12. This test paper with questions and answers for Class 12 Informatics Practices will be very useful for exams and help you to score good marks

Chapter 02 Data Handling using Pandas I Class 12 Informatics Practices Assignment

TOPIC – SERIES

Question. Create a series and print those elements which are divisible by 5
Answer: import pandas as pd
s1 = pd.Series([10, 21, 33, 14, 15])
print(s1)
for i in range(5):
if s1[i]%5==0:
print(s1[i])

Question. Create a series and print those elements which are multiples of 2.
Answer: import pandas as pd
s1 = pd.Series([10, 21, 33, 14, 15])
print(s1)
for i in range(5):
if s1[i]%2==0:
print(s1[i])

Question. Create a series such that data elements are twice that of index
Answer: import pandas as pd
import numpy as np
a=np.arange(1,5)
print(a)
ab=pd.Series(index=a,data=a*2)
print(ab)

Question. Print the even positions of numpy_series
Answer: import pandas as pd
array = np.arange(10,15)
numpy_series = pd.Series(array,index = [‘np1′,’np2′,’np3′,’np4′,’np5’])
Print the even positions of numpy_series
print(numpy_series[::2])

Question. Write program for multiplication of two series
Answer: import pandas as pd
Series1 = pd.Series([11,12,13,14,15])
Series2 = pd.Series([1,2,3,4,5])
Mul_series = Series1 * Series2
print(‘Series 1:-‘)
print(Series1)
print()
print(‘Series 2:-‘)
print(Series2)
print()
print(‘Multiplication: Series 1 * Series 2:-‘)
print(Mul_series)

Question. Write code to find the mean of all the elements in the Series
Answer: import pandas as pd
import numpy as np
dict1 = {‘Sachin’: 121, ‘Sourav’:100, ‘Dhoni’: 99, ‘Dravid’: 66, ‘Virat’: 75}
dict_series1 = pd.Series(dict1)
print(dict_series1.mean()) #MEAN – Aggregate Function.

Question. If s = pd.Series([‘a’,’b’,’c’,’d’,’e’]) is a series then what will be the output of the following:
print(s.iloc[:2])
print(s.iloc[2:3])
Answer: 0 a
1 b
dtype: object
2 c
dtype: object

Question. Print numpy series from np1 to np4 with a step of 2.
import pandas as pd
import numpy as np
array = np.arange(10,15)
s = pd.Series(array,index =[‘np1′,’np2′,’np3′,’np4′,’np5’])
Answer: print(s[‘np1’: ‘np4’:2])

Question. Write program for division of two series
Answer: import pandas as pd
import numpy as np
Series1 = pd.Series([11,12,13,14,15])
Series2 = pd.Series([1,2,3,4,5])
IntDivide_series = Series1 // Series2
print(‘Series 1:-‘,Series1)
print()
print(‘Series 2:-‘,Series2)
print()
print(‘Integer Division : Series 1 // Series 2:-‘)
print(IntDivide_series)

Question. Write code to compare two series.
Answer: import pandas as pd
ds1 = pd.Series([2, 4, 6, 8, 10])
ds2 = pd.Series([1, 3, 5, 7, 10])
print(“Series1:”,ds1)
print(“Series2:”,ds2)
print(“Compare the elements of the said Series:”)
print(“Equals:”)
print(ds1 == ds2)
print(“Greater than:”)
print(ds1 > ds2)
print(“Less than:”)
print(ds1 < ds2)

 

TOPIC – DATAFRAME

Consider the following Data Frames:

CBSE-Class-12-Informatics-Practices-Data-Handling-using-Pandas-Assignment-Set-B

 

Write the commands to do the following operations on the Data Frames given below:

Question. To create the Data Frames df1 and df2.
Answer: Hint- df1=pd.DataFrame({‘CS’:[85,45,55,65],’IP’:[60,40,50,58]})

Question. To add Data Frame df1 and df2.
Answer: Hint- df1.add(df2)

Question. To subtract Data Frame df2 from df1.
Answer: Hint- df1.sub(df2)

Question. To replace all NAN’s in Data Frame df1 to ‘No Value’.
Answer: Hint- df1.fillna(‘No Value’)

Question. To Write a command in python to Print the total number of records in the DataFrame df1.
Answer: Hint- print(df1.count())

Question. To Find the total of all the values of CS column in DataFrame df1.
Answer: Hint- df1[‘CS’].sum()

Question. To Rename column CS as ComputerSc in Data Frame df1.
Answer: Hint- df1.rename(columns={‘CS’:’ComputerSc’})

Question. To add a new column Total in Data Frame df1 whose value is equal to the total of both the existing columns values.
Answer: Hint- df1[‘Total’]=df1[‘CS’]+df1[‘IP’]

Question. To change the index of Dta Frame df2 from 0,1,2,3 to a,b,c,d
Answer: Hint- df2.rename(index={0:’a’,1:’b’,2:’c’,3:’d’})

Question. To display those rows in Data Frame df1 where value of CS column is more than 45.
Answer: Hint- print(df1[df1[‘CS’]>45])

 

TOPIC – DataFrame : export and import to and from csv file

Question. If we export DataFrame with separator other than comma than which one of the following is true?
a) While importing back it merges the columns
b) While importing back it gets imported as it was
c) We cannot export DataFrame with separator other than comma
d. None of these

Answer: A

Question. A DataFrame df1 is exported using the command ‘df1.to_csv(‘file1.csv)’ now if we import back into a DataFrame then it will ______
a) have an ‘unknown column’
b) not have ‘Unknown column’
c) be imported as it was
d) The DataFrame cannot be exported by the given command

Answer: A

Question. A DataFrame df1 is exported using the command ‘df1.to_csv(‘file1.csv)’ now the csv file will be created (location) ______
Answer: In the current folder(The folder where the python program located)Question. Suppose we want to export a DataFrame ‘df1’ to the csv file ‘data1.csv’ in a folder ‘mycsv’ under drive ‘D’ without index. Please write the export command.
Answer: df1.to_csv(r’d:\mycsv\data1.csv’, index=False) or df1.to_csv(’d:/mycsv/data1.csv’, index=False)

Question. Write a python program to export the following DataFrame to the csv file ‘csvfile.csv’ in current folder without the index and column names of the DataFrame.
       designation        salary

0      manager             25000
1      clerk                   16000
2 salesman 12000

Answer: d={‘Designation’:[‘manager’,’clerk’,’salesman’]
,’Salary’:[25000,16000, 12000]}
df=pd.DataFrame(d)
df.to_csv(‘csvfile.csv’, index= False, header=False)

 

Question. A DataFrame having two columns is exported to the csv file ‘csvfile.csv’ without index and column name in the current folder. Write a python program to import the file into a DataFrame with column names as ‘col1’ and ‘col2’ and display that.
Answer: import pandas as pd
df1=pd.read_csv(‘csvfile.csv’, names=[‘col1’, ‘col2’])
print(df1)

Question. Write a python program to import data from two csv files ‘file1.csv’ and ‘file2.csv’ and export them to a single csv file ’file3.csv’. All files are in current folder and are exported without index
Answer: import pandas as pd
df1=pd.read_csv(‘file1.csv’)
df2=pd.read_csv(‘file2.csv’)
df3=df1.append(df2)
df3.to_csv(‘file3.csv’, index= False)

Question. The following DataFrame ‘df1’ is exported using the command ‘df.to_csv(‘file1.csv’, index=False, header=False)’. Now write the output of the given python program.
       designation        salary
0      manager             20000
1      clerk                   17000
2      salesman           15000
3      director               30000
import pandas as pd
df1=pd.read_csv(‘file1.csv’,names=[‘xyz’, ‘abc’])
print(df1)

Answer: 
            xyz                    abc
0      manager             20000
1      clerk                   17000
2      salesman           15000
3      director               30000

Question. The following DataFrame‘df1’ is exported using the command ‘df.to_csv(‘file1.csv’, index=False)’. Now write the output of the given python program.
            xyz                    abc

0      manager             20000
1      clerk                   17000
2      salesman           15000
import pandas as pd
df1=pd.read_csv(‘file1.csv’, header=None)
print(df1)

Answer: 
              0                      1
0      manager             20000
1      clerk                   15000
2      salesman           22000

Question. Write a python program to export the following DataFrame to the csv file ‘csvfile.csv’ in current folder without the index of the DataFrame.
       designation        salary
0      manager             25000
1      clerk                   16000
2      salesman           12000

Answer: 
import pandas as pd
d={‘Designation’:[‘manager’,’clerk’,’salesman’] ,
‘Salary’:[25000,16000, 12000]}
df=pd.DataFrame(d)
df.to_csv(‘csvfile.csv’, index= False)

 

TOPIC – Data Visualisation

Question. The matplotlib Python library developed by ……………………… .
Answer: John Hunter.

Question. ………………… is a module in the matplotlib package.
Answer: Pyplot

Question. The matplotlib API is imported using …………………. .
Answer: Import

Question. The ……………………. is bounding box with ticks and labels.
Answer: Axes

Question. The ……………………. Can be plotted vertically or horizontally.
Answer: Bar chart

Question. Mr Manjeet want to plot a bar graph for the given set of values of subjects on x-axes and number of students who opted for the that subject on y-axes. Complete the code to perform the following operations:
a. To plot the bar graph in statement 1
b. To display the bar graph in statement 2
import matplotlib.pyplot as plt
x= [“Hindi”, “English”, “Maths”, “Science”]
y=[30,40,50,45]
………………… #statement 1
………………… #statement 2

Answer: a) plt.bar(x,y)
b) plt.show()

Question. Mr. Hamid wants to draw a line chart using a list of elements named Mylist. Complete the code to perform the following operations:
a. To plot a line chart using the given list Mylist.
b. To give a y-axes label to the line chart named Sample number.
import matplotlib.pyplot as plt
Mylist=[40,50,60,70,80,90]
……………………. # statement 1
……………………. # statement 2
plt.show()

Answer: a) plt.plot(Mylist)
b) plt.ylabel(“Sample number”)

Question. Write a Python program to draw a line using given axis values with suitable label in the x axis , y axis and a title.

 

CBSE-Class-12-Informatics-Practices-Data-Handling-using-Pandas-Assignment-Set-B-1

Answer: import matplotlib.pyplotas plt
x =[1,2,3]
y =[2,4,1]
plt.plot(x, y)
plt.xlabel(‘x – axis’)
plt.ylabel(‘y – axis’)
plt.title(‘Sample graph!’)
plt.show()

Question. What is the use of histtype attribute of hist() function of histogram? Mention and explain all it possible values.
Answer: histtype attribute is used to draw different types of histogram.
The type of histogram to draw.
a. ‘bar’ is a traditional bar-type histogram. If multiple data are given the bars are arranged side by side.
b. ‘barstacked’ is a bar-type histogram where multiple data are stacked on top of each other.
c. ‘step’ generates a lineplot that is by default unfilled.
d. ‘stepfilled’ generates a lineplot that is by default filled.

Question. Write a Python Program to plot line chart for values
x = [1,2,3,4,5]y=[65,45,76,26,80]
Answer: import matplotlib.pyplot as plt
import numpy as np
x=[1,2,3,4,5]
y=[65,45,76,26,80]
plt.plot(x,y)
plt.xlabel(“X axis”)
plt.ylabel(“Y axis “)
plt.title(“Graph for x=[1,2,3,4,5] y=[65,45,76,26,80]”)
plt.show()
#it will look like:

CBSE-Class-12-Informatics-Practices-Data-Handling-using-Pandas-Assignment-Set-B-2

 

Question. To add legends, titles and labels to a line plot with multiple lines.
Answer: import matplotlib.pyplot as plt
x=[1,2,3]
y=[5,7,4]
plt.plot(x,y,label=’First Line’,color=’red’)
x2=[1,2,3]
y2=[10,11,14]
plt.plot(x2,y2,label=’Second Line’,color=’black’)
plt.xlabel(‘Plot Number’)
plt.ylabel(‘Variables’)
plt.title(‘New Graph’)
plt.legend()
plt.show()
#it will look like

CBSE-Class-12-Informatics-Practices-Data-Handling-using-Pandas-Assignment-Set-B-3

 
 

Question. Write a Python Program to plot a bar chart horizontally
Answer: import matplotlib.pyplot as plt
import numpy as np
ob=(‘Python’,’C++’,’Java’,’Perl’,’Scala’,’Lisp’)
y_pos=np.arange(len(ob))
performance=[10,8,6,4,2,1]
plt.barh(y_pos,performance,align=’center’,color=’r’)
plt.yticks(y_pos,ob)
plt.xlabel(“Usage”)
plt.title(‘P.L.Usage’)
plt.show()
#it will look like:

CBSE-Class-12-Informatics-Practices-Data-Handling-using-Pandas-Assignment-Set-B-6

 

Question. Write the code for given bar chart:

CBSE-Class-12-Informatics-Practices-Data-Handling-using-Pandas-Assignment-Set-B-7

 

Answer: import matplotlib.pyplot as plt
plt.bar([0.25,1.25,2.25,3.25,4.25],[50,40,70,80,20],label=”Science”, width=.5)
plt.bar([0.75,1.75,2.75,3.75,4.75],[80,20,20,50,60],label=”Maths”,color=’r’,width=.5)
plt.legend()
plt.xlabel(“Months”)
plt.ylabel(“Subjects”)
plt.title(“Information”)
plt.show()

Question. Are bar charts and histograms the same?
Answer: No bar chart and histogram are not the same.
A bar chart has categories of data whereas histogram has number ranges.
The bar in bar chart has gap in between but the bins(bars) of histogram have no gap as number ranges are continuous.

Question. When should you create histograms and when should you create bar charts to present data visually?
Answer: Bar charts should be created when data is categorised. For example if the data consists of average expenditure in each month.
Histogram should be created when data is continuous. For instance if we have to plot the frequency of number between number range in an array. Histogram do not have the gaps between their bars.

Question. Write a program to create histogram that plot two ndarray x and y with 48 bins, in stacked horizontal histogram.
Answer: import matplotlib.pyplot as plt
x=[78,72,69,81,63,67,65,75,79,74,71,83,71,79,83,63]
y=[84,77,91,87,69,78,69,89,87,79,79,89,81,98,89,69]
plt.hist([x,y], bins=24, histtype=’barstacked’, cumulative=True, orientation=’horizontal’)
plt.show()
Write code to add title and axis titles to code of Question 22
import matplotlib.pyplot as plt
x=[78,72,69,81,63,67,65,75,79,74,71,83,71,79,83,63]
y=[84,77,91,87,69,78,69,89,87,79,79,89,81,98,89,69]
plt.hist([x,y], bins=24, histtype=’barstacked’, cumulative=True, orientation=’horizontal’)
plt.title(“Stackedbar Histogram”)
plt.xlable(“X-axis”)
plt.ylable(“Y-axis”)
plt.show()

Question. What is cumulative histogram? How do you create it using pyplot?
Answer: A cumulative histogram just keep adding its previous values to its present value. It is sum of all the previous bars plus its present bar in a normal histogram. A cumulative histogram is always increasing. For example if we want to know the number of cars sold till 1990,we can use cumulative histogram rather than adding all the bars together.
The argument cumulative = true is used to create cumulative histograms using pyplot. e.g.
plt.hist(x. bins=30, cumulative=true)

Question. Write a statement to plot a cumulative histogram of stacked bar type for ndarray x and y.
Answer: plt.hist( [x,y], histtype = ‘barstacked’, cumulative = True)

Question. Seema want to plot a cumulative histogram, he write following code:
import matplotlib.pyplot as plt
sale=[68,75,78,74,81,82,71,79,74,81,78,72]
plt.hist( sale, cumulative = False)
plt.show()
Above code didn’t show the cumulative histogram. What changes should Seema make?

Answer: import matplotlib.pyplot as plt
sale=[68,75,78,74,81,82,71,79,74,81,78,72]
plt.hist(sale, cumulative = True)
plt.show()

Question. Write a program to create a histogram for data=[1,11,15,21,31,33,35,37,41] and bins =[0,10,20,30,40,50,60] color of bars should yellow with red edge color.
Answer: import matplotlib.pyplot as plt
data=[1,11,15,21,31,33,35,37,41]
plt.hist(data,bins=[0,10,20,30,40,50,60], edgecolor=”red”, facecolor=’Yellow’)
plt.show()

Question. Write a Python Program to Plot a bar chart for values cities and population.
Answer: import matplotlib.pyplot as plt
import numpy as np
city=[‘Delhi’,’Mumbai’,’Chennai’,’Hyderabad‘]
p=[1500,2000,1800,1200]
plt.bar(city,p)
plt.xlabel(“City”)
plt.ylabel(“Population in Lacs “)
plt.title(“Population of different cities”)
plt.show()
#it will look like:

CBSE-Class-12-Informatics-Practices-Data-Handling-using-Pandas-Assignment-Set-B-4

Question. Write a Python Program to plot a bar chart with width.
Answer: import matplotlib.pyplot as plt
import numpy as np
y_axis=[20,50,30]
x_axis=range(len(y_axis))
plt.bar(x_axis,y_axis,width=.5,color=’orange’)
plt.show()
#it will look like:\

CBSE-Class-12-Informatics-Practices-Data-Handling-using-Pandas-Assignment-Set-B-5

Class 12 Informatics Practices Assignments
CBSE Class 12 Informatics Practices Concept Of Inheritance In Java
CBSE Class 12 Informatics Practices Database Concepts Assignment
CBSE Class 12 Informatics Practices Database Query using Sql
CBSE Class 12 Informatics Practices Database Transactions Assignment
CBSE Class 12 Informatics Practices Extensible Markup Language Assignment
CBSE Class 12 Informatics Practices Free And Open Source Software Assignment
CBSE Class 12 Informatics Practices GUI Dialogs And Tables Assignment
CBSE Class 12 Informatics Practices HTML I Basic HTML Elements Assignment
CBSE Class 12 Informatics Practices HTML II Lists Tables and Forms Assignment
CBSE Class 12 Informatics Practices Introduction to Computer Networks Assignment
CBSE Class 12 Informatics Practices IT Applications Assignment
CBSE Class 12 Informatics Practices Java Database Connectivity To MySQL Assignment
CBSE Class 12 Informatics Practices Java GUI Programming Revision Tour Assignment
CBSE Class 12 Informatics Practices More About Classes And Libraries Assignment
CBSE Class 12 Informatics Practices More on SQL Grouping Records and Table Joins Assignment
CBSE Class 12 Informatics Practices More RDBMS Assignment
CBSE Class 12 Informatics Practices MYSQL Revision Tour Assignment
CBSE Class 12 Informatics Practices Networking and open standards Assignment
CBSE Class 12 Informatics Practices Programming Fundamentals Assignment
CBSE Class 12 Informatics Practices Revision Assignment Set A
CBSE Class 12 Informatics Practices Revision Assignment Set C
CBSE Class 12 Informatics Practices Revision Assignment Set D
CBSE Class 12 Informatics Practices Web Application Development Assignment
CBSE Class 12 Informatics Practices Worksheet All Chapters

CBSE Class 12 Informatics Practices Chapter 02 Data Handling using Pandas I Assignment

We hope you liked the above assignment for Chapter 02 Data Handling using Pandas I which has been designed as per the latest syllabus for Class 12 Informatics Practices released by CBSE. Students of Class 12 should download and practice the above Assignments for Class 12 Informatics Practices regularly. We have provided all types of questions like MCQs, short answer questions, objective questions and long answer questions in the Class 12 Informatics Practices practice sheet in Pdf. All questions have been designed for Informatics Practices by looking into the pattern of problems asked in previous year examinations. You can download all Revision notes for Class 12 Informatics Practices also absolutely free of cost. Lot of MCQ questions for Class 12 Informatics Practices have also been given in the worksheets and assignments for regular use. All study material for Class 12 Informatics Practices students have been given on studiestoday. We have also provided lot of Worksheets for Class 12 Informatics Practices which you can use to further make your self stronger in Informatics Practices.

What are benefits of doing Assignment for CBSE Class 12 Informatics Practices Chapter 02 Data Handling using Pandas I?

a. Score higher marks: Regular practice of Informatics Practices Class 12 Assignments for chapter Chapter 02 Data Handling using Pandas I will help to improve understanding and help in solving exam questions correctly.
b. As per CBSE pattern: All questions given above follow the latest Class 12 Informatics Practices Sample Papers so that students can prepare as per latest exam pattern.
c. Understand different question types: These assignments include MCQ Questions for Class 12 Informatics Practices with answers relating to Chapter 02 Data Handling using Pandas I, short answers, long answers, and also case studies.
d. Improve time management: Daily solving questions from Chapter 02 Data Handling using Pandas I within a set time will improve your speed and accuracy.
e. Boost confidence: Practicing multiple assignments and Class 12 Informatics Practices mock tests for Chapter 02 Data Handling using Pandas I reduces exam stress.

How to Solve CBSE Class 12 Informatics Practices Chapter 02 Data Handling using Pandas I Assignment effectively?

a. Start with Class 12 NCERT and syllabus topics: Always read the chapter carefully before attempting Assignment questions for Class 12 Informatics Practices Chapter 02 Data Handling using Pandas I.
b. Solve without checking answers: You should first attempt the assignment questions on Chapter 02 Data Handling using Pandas I yourself and then compare with provided solutions.
c. Use Class 12 worksheets and revision notes: Refer to NCERT Class 12 Informatics Practices worksheets, sample papers, and mock tests for extra practice.
d. Revise tricky topics: Focus on difficult concepts by solving Class 12 Informatics Practices MCQ Test.
e. Maintain notebook: Note down mistakes in Chapter 02 Data Handling using Pandas I assignment and read them in Revision notes for Class 12 Informatics Practices

How to practice CBSE Class 12 Informatics Practices Chapter 02 Data Handling using Pandas I Assignment for best results?

a. Solve assignments daily: Regular practice of Chapter 02 Data Handling using Pandas I questions will strengthen problem solving skills.
b.Use Class 12 study materials: Combine NCERT book for Class 12 Informatics Practices, mock tests, sample papers, and worksheets to get a complete preparation experience.
c. Set a timer: Practicing Class 12 Informatics Practices Chapter 02 Data Handling using Pandas I assignment under timed conditions improves speed and accuracy.

Where can I download in PDF assignments for CBSE Class 12 Informatics Practices Chapter 02 Data Handling using Pandas I

You can download free Pdf assignments for CBSE Class 12 Informatics Practices Chapter 02 Data Handling using Pandas I from StudiesToday.com

How many topics are covered in Chapter 02 Data Handling using Pandas I Informatics Practices assignments for Class 12

All topics given in Chapter 02 Data Handling using Pandas I Informatics Practices Class 12 Book for the current academic year have been covered in the given assignment

Is there any charge for this assignment for Chapter 02 Data Handling using Pandas I Informatics Practices Class 12

No, all Printable Assignments for Chapter 02 Data Handling using Pandas I Class 12 Informatics Practices have been given for free and can be downloaded in Pdf format

Are these assignments for Chapter 02 Data Handling using Pandas I Class 12 Informatics Practices designed as per CBSE curriculum?

Latest syllabus issued for current academic year by CBSE has been used to design assignments for Chapter 02 Data Handling using Pandas I Class 12

Are there solutions or answer keys for the Class 12 Informatics Practices Chapter 02 Data Handling using Pandas I assignments

Yes, we have provided detailed answers for all questions given in assignments for Chapter 02 Data Handling using Pandas I Class 12 Informatics Practices