11,12, 13, 14operations On DF
11,12, 13, 14operations On DF
11,12, 13, 14operations On DF
Operations on DF
1 Which function is used to find values from a DataFrame D using the index
number?
a) D.loc
b) D.iloc
c) D.index
d) None of these
2 Which attribute of a dataframe is used to convert rowa into columns and
columns into rows in a dataframe?
a) T
b) ndim
c) empty
d) shape
3 A DataFrame has two axes
a) True
b) False
4 . ___________parameter is used to ignore row labels in
concatenation operation.
a) ignore_index=True
b) ignore_index=False
c) ignoreindex=’true’
d) index_ignore=’False
5 Which of the following is/are characteristics of DataFrame?
a) Columns are of different types
b) Can Perform Arithmetic operations
c) Axes are labeled (rows and columns)
d) All of the above
6 Which of the following function is used to create DataFrame?
a) DataFrame( )
b) NewFrame( )
c) CreateDataFrame( )
d) None of the Above
7 In given code dataframe ‘D1’ has _____ rows and _____ columns.
import pandas as pd
S1 = pd.Series([1, 2, 3, 4], index = ['a', 'b','c','d'])
S2 = pd.Series([11, 22, 33, 44], index = ['a', 'bb','c','dd'])
D1 = pd.DataFrame([S1,S2])
a) 2, 4
b) 4, 6
c) 4, 4
d) 2, 6
8 Assertion (A):
Nidhi has create dataframe Df1
Worksheet 13 Date
3. Choose the right code from the following for statement 1.
1 i. pd
ii. df
iii. data
iv. p
3. Choose the right code from the following for the statement 2.
2 i. Dataframe
ii. DataFrame
iii. Series
iv. Dictionary
3. Choose the correct statement/ method for the required output: (5,3)
3 i. df.index
ii. df.shape()
iii. df.shape
iv. df.size
3. He wants to print the details of "January" month along with the
4 number of passengers, Identify the correct statement:
i. df.loc[['Month','Passengers']][df['Month']=='Jan']
ii. df[['Month','Passengers']][df['Month']=='Jan']
iii. df.iloc[['Month','Passengers']][df['Month']=='Jan']
iv. df(['Month','Passengers']][df['Month']=='Jan')
3. Mr. Ankit wants to change the index of the Data Frame and the
5 output for the same is given below. Identify the correct statement to
change the index.
i. df.index[]=["Air India","Indigo","Spicejet","Jet","Emirates"]
ii. df.index["Air India","Indigo","Spicejet","Jet","Emirates"]
iii. df.index=["Air India","Indigo","Spicejet","Jet","Emirates"]
iv. df.index()=["Air India","Indigo","Spicejet","Jet","Emirates"]
3. Consider the folloowing dataframe and do as directed:
6 import pandas as pd
d={‘Mouse’:[150,200,300,400],
‘Keyboard’:[180,200,190,300],
‘Scanner’:[200,280,330,450]}
df=pd.DataFrame(d,index=[‘Jan’,’Feb’,’March’,’April’])
Which of the following code will print names and Annual marks of
students?
a) print(df.loc[:,’Name’:’AnnualExam’])
b) print(df.loc[‘Name’:’AnnualExam’])
c) print(df.loc[:,df.columns!=’InternalMarks’])
d) All of these
2 Ms. Kavitha wants to print a single column from the dataframe, which
of the following is correct syntax for her?
a) df(col)
b) df<col>
c) df[col]
d) df{df:col}
3 Which of the following is the correct syntax to select or access
columns from the dataframe using column names?
a) df(col1,col2,…,coln)
b) df[[col1,col2,…,coln]]
c) df[col1,col2,…,coln]
d) df{col1:col2:…,:coln}
4 df.index properties can be used to
i. rename rows
ii. rename columns
iii. rename rows and columns both
iv. None of these
5