WorksheetsPandas
Total questions: 20
Worksheet time: 7mins
What does the df.head(5) function do in pandas?
Shows the last 5 rows
Shows the first 5 rows
Deletes the first 5 rows
Returns column names
Which of the following creates a DataFrame from a dictionary?
df = pandas.Series({‘a’: 1, ‘b’: 2})
df = pandas.DataFrame([1,2,3])
df = pandas.DataFrame({‘a’: [1,2], ‘b’: [3,4]})
df = pandas.read_dict({‘a’: [1,2], ‘b’: [3,4]})
What does df.groupby('column_name') return?
A grouped object that can be aggregated
A sorted DataFrame
A filtered DataFrame
A new column
What will df.iloc[2, 1] return?
A list of two values
The 2nd row, 1st column value
The 3rd row, 2nd column value
An error
Which pandas function helps combine multiple DataFrames vertically (row-wise)?
concat()
merge()
combine()
join()
What is the default axis for df.sum()?
1 (row-wise)
None
It doesn’t have a default
0 (column-wise)
What does df.sort_values(by='price', ascending=False) do?
Sorts rows by column price in ascending order
Sorts columns in descending order
Sorts rows by column price in descending order
Throws an error
What is the result of df['A'] > 10?
A list of values greater than 10
A Series of Boolean values
An error
A filtered DataFrame
Which of the following returns summary statistics of numerical columns?
df.describe()
df.stats()
df.summary()
df.profile()
What does df.isnull().sum() return?
Total number of missing values
Sum of all non-null entries
A DataFrame of all missing values
Count of NaNs in each column
Which method is used to return a DataFrame with duplicate rows removed?
dropna()
remove_duplicates()
drop_duplicates()
filter_duplicates()
What does df.loc[2] return?
Row number 2 (zero-based)
Only the value of column index 2
Row with index label 2
Value in row 2 and column labeled ‘2’
What does df.value_counts() return when applied to a Series?
Count of unique values in that Series
Count of column names
Count of nulls
Frequency of rows
What does df.groupby('brand')['price'].mean() return?
A pivot table
Grouped average of prices by brand
Mean price across all brands
Total price for each brand
Which of the following fills missing values forward (downward) in a column?
df.fillna(method='ffill')
df.fillna('forward')
df.interpolate()
df.fillna(method='bfill')
What does df[df['age'] > 30] return?
Error
Only the age column
Boolean array
All rows where 'age' is greater than 30
Which method combines two DataFrames side-by-side by column?
df1.combine_first(df2)
pd.concat([df1, df2], axis=1)
df1.merge(df2)
df1.append(df2)
What will df[df.duplicated()] return?
Only rows that are not duplicated
Boolean list of duplicated rows
Count of duplicates
DataFrame with duplicate rows
What will df.groupby('gender')['income'].mean() return?
Median income per gender
Mean income per gender
A DataFrame with all columns
Count of gender-wise records
To drop a row with a specific index value '5', you should use:
df.drop('5', axis=1)
df.remove(5)
df.drop(index=5)
df.drop(5)
