Averageqp (2)

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

MCQS

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

13 Consider the dataframe df


PCD title price qty
0 p01 notebook 85 500
1 p02 pencilbox 76 200
2 p03 waterbottle 129 50
3 p04 schoolbag 730 70
i) Predict the output of the following statement
i . df.size
ii. df.iloc[1:3 , 1: ]
iii ) Write the python statement to add a new column ACC_NO ( with values as - [ 135, 153, 225,442]) before the qty column
iv. Write the python statement to compute and display the details of those items whose price is in between 80 and 150 (both inclusive)

14 Predict the output of the following statement


i ) df. ndim
ii) print( df.empty )
iii) Write the python statement to display the details price of items less than 100

15 Consider the above dataframe namelist


i) Write statement to display product and its price
ii) Shopper needs to know the cost of waterbottle . help him to identify the correct statement
a) namelist1=namelist[namelist['title']=='waterbottle'] b) namelist1 = namelist['title'=='waterbottle']
print(namelist1) print(namelist1)
c) namelist1 = namelist[namelist.title='waterbottle']
print(namelist1)
iii) Which of the following statements will delete column 'total' from df
i) df.pop('total') ii) del df['total'] iii) del (df.total) iv) df.del('total')

16 Write a program to print the dataframe nameless, one column at a time


MCQS

1 b) from pandas import DataFrame


2 d) A.head(3)
3 d) size
4 c) 3
5 a) classdf.sort_values(by=['mark'])
2MARKS
6 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)
print(namelist)

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'})

12 i) saranya aditi maries


eng 92 86 73
math 88 89 81
hindi 93 98 92

ii) eng maths science hindi


saranya 92 88 82 93
aditi 86 89 87 98
maries 73 81 56 92

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 ( "----------")

You might also like