0
0
Pandasdata~5 mins

Filling missing values with fillna() in Pandas - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AIt does nothing and returns the original data
BIt fills missing values with zero
CIt raises an error
DIt fills missing values with the mean
Which fillna() method fills missing values using the next valid value?
Amethod='ffill'
Bvalue='mean'
Cvalue=0
Dmethod='bfill'
How do you fill missing values in multiple columns with different values using fillna()?
APass a list of values
BPass a dictionary with column names and values
CCall <code>fillna()</code> multiple times
DUse <code>method='ffill'</code>
What does inplace=True do in fillna()?
ADeletes missing values
BReturns a copy with filled values
CModifies the original data directly
DRaises an error if missing values exist
Which of these is NOT a valid way to fill missing values with fillna()?
AUsing <code>fillna()</code> without any arguments
BUsing a method like 'ffill'
CUsing a dictionary for different columns
DUsing a scalar value like 0
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.