1.Which of the following methods is used to group data of a data frame, based on specific columns?
- groupby
- aggregate
- group
- groupat
Answer: 1)groupby
2.What does the
expression df.iloc[:, lambda x : [0,3]] do? Consider a data frame df with
columns ['A', 'B', 'C', 'D'] and rows ['r1', 'r2', 'r3'].
- Selects Column 'A' and 'C'
- Results in Error
- Selects Columns 'A', 'B', and 'C'
- Selects Column 'A' and 'D'
Answer: 4)Selects
Column 'A' and 'D'
3.Consider a data
frame df with 10 rows and index [ 'r1', 'r2', 'r3', 'row4', 'row5', 'row6',
'r7', 'r8', 'r9', 'row10']. What does the expression g =
df.groupby(df.index.str.len()) do?
- Groups df based on index values
- Groups df based on length of each index value
- Groups df based on index strings
- Data frames cannot be grouped by index values.
Hence it results in Error.
Answer: 4)Data
frames cannot be grouped by index values. Hence it results in Error.
4.Consider a data
frame df with columns ['A', 'B', 'C', 'D'] and rows ['r1', 'r2', 'r3'], Which
of the following expression is used to extract columns 'C' and 'D'?
- df.loc[:, lambda x : x.columns.isin(['C',
'D'])]
- df[:, lambda x : x.columns.isin(['C', 'D'])]
- lambda x : x.columns.isin(['C', 'D'])
- None
Answer: 1)df.loc[:,
lambda x : x.columns.isin(['C', 'D'])]
5.Which of the
following method can be applied on a groupby object to get the group details?
- group_details
- groups
- get_groups
- fetch_groups
Answer: 2)groups
6.Consider a data
frame df with 10 rows and index [ 'r1', 'r2', 'r3', 'row4', 'row5', 'row6',
'r7', 'r8', 'r9', 'row10']. How many rows are obtained after executing the
below expressions
g =
df.groupby(df.index.str.len())
g.filter(lambda x:
len(x) > 1)
- 9
- 1
- 5
- 10
Answer: 1)9
7.Consider a data
frame df with columns ['A', 'B', 'C', 'D'] and rows ['r1', 'r2', 'r3']. What
does the expression df[lambda x : x.index.str.endswith('3')] do?
- Returns the row name r3
- Results in Error
- Returns the third column
- Filters the row labelled r3
Answer: 4)Filters
the row labelled r3
8.Consider a data
frame df with columns ['A', 'B', 'C', 'D'] and rows ['r1', 'r2', 'r3']. Which
of the following expression filters the rows whose column B values are greater
than 45 and column 'C' values are less than 30?
- df.loc[(df.B > 45) & (df.C < 30)]
- df[df.B > 45 & df.C < 30]
- df.loc[df.B > 45 & df.C < 30]
- (df.B > 45) & (df.C < 30)
Answer:
1)df.loc[(df.B > 45) & (df.C < 30)]
9.Consider a data
frame df with columns ['A', 'B', 'C', 'D'] and rows ['r1', 'r2', 'r3']. Which
of the following expression filters the rows whose column B values are greater
than 45?
- df.iloc[df.B > 45]
- df.B > 45
- df[df.B > 45]
- df.loc[B > 45]
Answer: 3)df[df.B
> 45]
10.Consider a data
frame df with 10 rows and index [ 'r1', 'r2', 'r3', 'row4', 'row5', 'row6',
'r7', 'r8', 'r9', 'row10']. What does the aggregate method shown in below code
do?
g =
df.groupby(df.index.str.len())
g.aggregate({'A':len,
'B':np.sum})
- Computes Sum of column A values
- Computes length of column A
- Computes length of column A and Sum of Column
B values of each group
- Computes length of column A and Sum of Column
B values
Answer: 3)Computes
length of column A and Sum of Column B values of each group


Post a Comment