Standardqp
Standardqp
MCQS
1 Which python library is not used for data science ?
a) Panda b) Numpy c) Matplotlib d)Tkinter
2 Dataframe in pandas can be created from which of the following
a) series b) List of dictionaries c) Structured ndarray d) All of these
3 Pandas mainly used for
a) Data Recovery b) Data Backup c) Data Visualization d) Data Analysis
4 ________ method in pandas can be used to change the index of rows and columns of a series or dataframe
a) rename() b) reindex() c) reframe() d)All of these
5 To display the 3rd,4th and 5th columns from the 6th to 9th rows of a dataframe you can write
a) DF.loc[6:9,3:5] b) DF.loc[6:10 , 3:6] c) DF.iloc[6:10 , 3:5] d) DF.iloc[6:9, 3:5]
2 Marks
6 Consider the dataframe classframe . Write the python code to create dataframe using list of dictionaries
Rollno Name Class Stream
st1 1 Arthi IX Science
st2 2 Preethi X Arts
st3 3 Karthi NaN NaN
st4 4 Lakshmi X Commerce
7 Consider the above dataframe
i) Write the statement to display the names in ascending order
ii) Write the statement to fill the missing value class by ' x ' and stream by 'commerce'
iii) Write the statement to display the number of values under each column
iv) Write the statement to find missing data in given dataframe
8 Write a pythonn code to create a dataframe with appropriate headings from the list given below
['S101' , 'Sharmi' , 70] , ['S102' , ' Bindhi' , 69 ] , [ 'S103' , 'Sovrav' , 75] , [' S105 ' , ' Soundar ' , 89]
9 Suppose a dataframe named df contains information about student having column rollno , name , class , section . Write the code for the for the following d
i) Add one more column as fee
ii) Rename column fee as 'qfee'
10 iii) Write python code to delete column fee of dataframe and display df
iv) Write the python code to display the fee for the complete year from dataframe but column 'fee' has fee for one month
3 Marks
11 Consider the following dataframe , classframe
i) Add a new column 'Grade' to the dataframe
ii) Add a new row with values (5,sadhana, X , science)
iii) Display name of all rows
13 Consider the above dataframe provision. What will be the output produced by following statement
i) print ( provision.loc [ : , 'QTY': ])
ii) print( provision . iloc [2: , : 3 ])
iii) print ( provision . iloc [1:3 , 2:3 ] )
14 Consider the above dataframe classframe , Predict the output of the following python statement
1 ) classframe . shape
2) classframe [1:2]
3) Write the python statement to display the total number of rows in classframe
16 Write a program to print only the values from stream column for each row
17 Write a statement to display top rows values of item in dataframe provision and last 3 values of price column
DATAFRAME - STANDARD QP
1 d) Tkinter
2 d) All of these
3 d) DataAnalysis
4 b) reindex()
5 a) df.loc[6:10,3:5]
6 import pandas as pd
data=[{'rollno' :1,'name':'Arthi' , 'class': ' ix' , 'stream':'science'},
{'rollno':2,'name':'preethi','class':'ix','stream':'arts'},
{'rollno':3,'name':'karthi','class':NaN,'stream':NaN},
{'rollno':4,'name':'lakshmi','class':'X','stream':'commerce'}]
classframe=pd.DataFrame(data)
print(classframe)
7 i) print(classframe.sort_values(by=['name'])
ii) classframe=classframe.fillna({'class':'X','stream':'commerce'})
iii) print(classframe.count(0)), or classframe.count(axis='index')
iv) classframe.isnull()
8 import pandas as pd
data=[['S101' , 'Sharmi' , 70] , ['S102' , ' Bindhi' , 69 ] , [ 'S103' , 'Sovrav' , 75] , [' S105 ' , ' Soundar ' , 89]]
df=pd.DataFrame(data, columns=['Rollno','Name','Mark'])
print(df)
9 i) df['fee'] =5000
ii) df=df.rename(columns={'fee':'qfee'})
11 i) classframe['grade']=['A','B','B','C']
ii) classframe.loc['st5']=[5,'sadhana','X','science']
iii) print(classframe['name'])
12 i) print(provision.loc[:][provision['city']=='chennai'])
ii) provision['net_price'] = provision['Qty']*provision['price']
iii) print(provision[provision['qty']>100])
iii)
city
102 Kolkata
103 Darjeeling
14 i) (4,4)
ii)
Rollno name class stream
st2 2 Preethi X Arts
iii) print(len(classframe))
15 I) provision=provison.drop(columns=['price'])
ii) provision.index=['A','B','C','D','E']
iii) provision=provision.drop(index=[101,104])
16 import pandas as pd
data=[{'rollno' :1,'name':'Arthi' , 'class': ' ix' , 'stream':'science'},
{'rollno':2,'name':'preethi','class':'ix','stream':'arts'},
{'rollno':3,'name':'karthi','class':NaN,'stream':NaN},
{'rollno':4,'name':'lakshmi','class':'X','stream':'commerce'}]
classframe=pd.DataFrame(data)
for r , row in classframe.iterrows( ):
print( row ['stream'])
print("---------")
17 print(provision.item.head(2))
print(provision.price.tail(3))