You are on page 1of 2

Sarvodaya Public School Python Pandas Questions with Answer

Azamgarh By Ashraf Jamal

Q.1 Which function is used to sort a dataframe?


Q.2 What will be the output of following code:
import pandas as pd
import numpy as np
Arr1 = np.array([ [1,2,3],[4,5,6] ])
df = pd.DataFrame(Arr1, columns = [ 'num1','num2','num3'])
print (df.iloc[0,2] )

Q.3 In pandas, S in a series with following data :


S=pd.Series([5,10,15,20,25])
Find the output of :S[1:3]

Q. 4 State true/false

Q. 5 Which method is used to change the name of the existing indexes/column-label in a


DataFrame?
Ans, rename()
Q. 6 Write syntax/example to create a histogram.

Q. 7 What is pivoting? What is the shortcoming of pivot()?


Q. 8 Consider following two arrays:
Ar1=np.array([[0,1,2],[3,4,5]])
Ar2= np.array([[10,11,12],[13,14,15]])
Write command to concatenate both arrays i) row wise ii)column wise
Q. 9 Write code to create and display a 1D ndarray of size 10 with all elements as zero, but the fifth
element is 10
OR
Write a code to create and display a 2D ndarray of shape (5,2). The element must lies between 10
and 30 and gap between the elements must be equal.

Q. 10 Explain following terms of NumPy arrays:


i)Rank ii) Shape iii) ItemSize

Q. 11 Given two ndarrays:


A=np.array([1,2,3,4,5])
B= np.array([3,4,0,-1,-3])
Write code to calculate:
i ) Covariance ii) correlation iii) regression
Q. 12 A dictionary Grade contains the following:
Grade={‘Name’:[ ‘Rashmi’,’Harsh’,’Ganesh’, ‘Priya’,’Vivek’],
‘Grade’:[‘A1’,’A2’,’B1’,’A1’,’B2’]}
Write statements for the following:-
i) Create a Dataframe named “Gr”.
ii) Add a column called ‘marks’ with following data:
[97,92,95,89,96,82]
iii) Delete 3rd and 5th rows,
i) Gr.drop([2,4])
Q. 13 Given the dataframe weather do following:-
i) Write command to compute sum of every column.
ii) Write command to compute mean of column “Rainfall”
iii) Write command to compute average of all the columns for last 10 rows only
iv) Write command to compute sum of every rows.

You might also like