Professional Documents
Culture Documents
Averageqp (2)
Averageqp (2)
Averageqp (2)
1 Which of the following statements will import dataframe from pandas library
a) import DataFrame from pandas b) from pandas import DataFrame
c) import DataFrame from pandas d) from Pandas import DataFrame
2 To display first three rows of a datafrma object 'A'. you may write :
a) A.Head() b) A.Tail(3) c) A.Head(3) d) A. head(3)
3 Which attribute is used to get total number of elements in a dataframe
a) values b) shape c) ndim d) size
4 The following code create a dataframe named 'Doll' with _________ columns
import pandas as pd
Doll=pd.DAtaFrame(['sai','krish','siva'])
a) 1 b) 2 c) 3 d) 4
5 Consider the following DataFrame class_df having columns name,class and mark
Select the correct statement from the following to get the sorted value of the column marks
a) class_df.sort_values(by=['mark']) b) class_df.sort(['mark'])
c) sort(class_df) d) sort_values(class_df['marks'])
2 Marks
6 Consider the dataframe namelist , create the dataframe using dictionary of series
Eng Math Hindi
saranya 92 88 93
Aditi 86 89 98
Maries 73 81 92
7 Consider the above dataframe namelist
i. List the column name of dataframe
ii. Write the statement to find size of dataframe and its output
iii. Wrtite the statement to change the index of the dataframe ['S','A','M']
iv. Write the statement to find values in dataframe and its output
8 Write the python statement to
i) add a new student ['vishal',78,90,73]
ii) add a new column total by adding the marks of all subjects
iii) Remove the column total
iv) change the name of the columns as 'English','Maths','Hindi'
9 CArefully observe the following code
import pandas as pd
q1={'X1':3000,'X2':4000,'X3':2000,'X4':1600}
q2={'A':23000,'B':24000,'C':22000}
price={1:q1,2:q2}
df=pd.Dataframe(price)
print(df)
i) List the index of the dataframe df
ii) list the column names of dataframe df
10 i)Write the statement to access the column eng, hindi from dataframe classlist using loc
ii) Write statement to access english mark of saranya and maries
iii) write the statement to get the output 98
iv) Write the statement to access all datails of dataframe
3 MARKS
11 Consider the following dataframe and write the command to perform following operation on the dataframe class1 and class2
class1 class2
Eng ,Maths , Hindi Eng, Maths, Hindi
0 43 , 42 , 40 0 32 , 53 , 31
1 23,41,53 3 54 , 21, 65
2 64,57 , 62 4 31, 73 , 36
3 12 , 14 , 17 5 21, 51 ,43
i. To subtract class2 from class1 and its output
ii. To add class 1 and class2 and its output
iii. To change the index label of class1 from 2 to two and from 3 to three
12 Consider the above dataframe namelist , predict the output of the following statement
i) print(namelist.T)
ii) namelist.insert (2 , 'science', [82,87,56])
print(namelist)
iii) write the python statement to compute and display the details of those students whose total marks less than 250
7 i)index(['eng','math','hindi'],dtype=object)
ii)namelist.size , o/p : 9
iii) namelist.index=['S','A','M']
iv) namelist.values
92 88 93
86 89 98
73 81 92
8 i) namelist.loc['vishal']=[78,90,73]
ii) namelist['total'] = namelist ['Eng'] +namelist['math']+namelist['hindi']
iii) namelist= namelist . drop (columns= ['total'])
iv) namelist= namelist.rename (columns={'eng':'English','math':'maths','Hindi':'Hindi'})
9 i) index(['X1','X2','X3','X4','A','B,'C'],dtype=object)
ii) index ([1,2],dtype=int64)
10 i) namelist.loc[:,['eng','hindi']]
ii) namelist.loc[['saranya','maries'],'eng']
iii) namelist.at['aditi','hindi']
iv) namelist[ : ] or namelist .loc[: , :]
3MARKS
11 I) print(class2-class1)
eng maths hindi
0 -11 11 -9
1 NaN NaN NaN
2 NaN NaN NaN
3 42 7 48
4 NaN NaN NaN
5 NaN NaN NaN
ii) print(class1+class2)
eng maths hindi
0 75 95 71
1 NaN NaN NaN
2 NaN NaN NaN
3 66 35 82
4 NaN NaN NaN
5 NaN NaN NaN
iii) class1=class1.rename(index={2:'two',3:'three'})
iii) namelist['total]=namelist['eng']+namelist['math']+namelist['hindi']
print(namelist[namelist['total'] <250])
13 i) 16
ii) title price qty
p02 pencilbox 76 200
p03 waterbottle 129 50
iii) df.insert(3,'Acc_no',[135,153,225,442])
iv) df.loc[ :] [df[ 'price'] >=80 and df['price']<=150]
14 i) 2
ii) False
iii) print(df[df['price']<100])
15 i)df[['title','price']]
ii) a)
iii) b)
16 import pandas as pd
s1=pd.Series([92,86,73],index=['saranya','aditi','maries'])
s2=pd.Series([88,89,81],index=['saranya','aditi','maries'])
s3=pd.Series([93,98,92],index=['saranya','aditi','maries'])
data={'eng':s1,'math':s2,'hindi':s3}
namelist=pd.DataFrame(data)
for i, j in nameless.iteritems( ):
print(j)
print ( "----------")