Recall & Review
beginner
What does the
fillna() function do in pandas?The
fillna() function replaces missing values (NaN) in a DataFrame or Series with a specified value or method.Click to reveal answer
beginner
How can you fill missing values with the mean of a column using
fillna()?Calculate the mean of the column and pass it to
fillna(). For example: df['col'].fillna(df['col'].mean(), inplace=True).Click to reveal answer
intermediate
What does the parameter
method='ffill' do in fillna()?It fills missing values by propagating the last valid observation forward to the next missing value.
Click to reveal answer
intermediate
Can
fillna() fill missing values differently for each column in a DataFrame?Yes, by passing a dictionary with column names as keys and fill values as values, e.g.,
df.fillna({'A': 0, 'B': 1}).Click to reveal answer
beginner
What happens if you use
fillna() without inplace=True?It returns a new DataFrame or Series with missing values filled, but does not change the original data unless you assign it back or use
inplace=True.Click to reveal answer
What is the default behavior of
fillna() if no value or method is specified?✗ Incorrect
If no value or method is specified, fillna() returns the original data unchanged.
Which
fillna() method fills missing values using the next valid value?✗ Incorrect
method='bfill' fills missing values by using the next valid value (backward fill).
How do you fill missing values in multiple columns with different values using
fillna()?✗ Incorrect
Passing a dictionary like {'col1': val1, 'col2': val2} fills each column with its specified value.
What does
inplace=True do in fillna()?✗ Incorrect
inplace=True changes the original DataFrame or Series without needing assignment.
Which of these is NOT a valid way to fill missing values with
fillna()?✗ Incorrect
fillna() without arguments does not fill missing values and returns data unchanged.
Explain how you would fill missing values in a DataFrame column with the column's median using
fillna().Think about how to get the median and pass it to fillna.
You got /3 concepts.
Describe the difference between using
method='ffill' and method='bfill' in fillna().Consider the direction of filling missing values.
You got /3 concepts.