0
0
Data Analysis Pythondata~5 mins

Filling missing values (fillna) in Data Analysis Python - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the fillna() function do in data analysis?

The fillna() function replaces missing values (NaN) in a dataset 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())

Click to reveal answer
intermediate
What is the difference between filling missing values with a constant and using a method like 'ffill' in fillna()?

Filling with a constant replaces all missing values with the same value. Using method='ffill' fills missing values with the last known non-missing value above it.

Click to reveal answer
beginner
Can fillna() be used to fill missing values in both Series and DataFrames?

Yes, fillna() works on both pandas Series and DataFrames to fill missing values.

Click to reveal answer
intermediate
What happens if you use fillna() without assigning the result back to the DataFrame or using inplace=True?

The original DataFrame remains unchanged because fillna() returns a new object by default unless inplace=True is set.

Click to reveal answer
Which method fills missing values by copying the previous non-missing value downwards?
Amethod='ffill'
Bmethod='bfill'
Cvalue=0
Ddropna()
What does df['age'].fillna(df['age'].mean()) do?
ADrops rows where 'age' is missing
BFills missing 'age' values with the average age
CFills missing 'age' values with zero
DLeaves missing values unchanged
If you want to fill missing values with a fixed number, which parameter do you use in fillna()?
Avalue
Bmethod
Cinplace
Daxis
What is the default behavior of fillna() regarding modifying the original DataFrame?
AModifies original DataFrame by default
BRaises an error if missing values exist
CReturns a new DataFrame with filled values
DDeletes rows with missing values
Which of these is NOT a valid way to fill missing values using fillna()?
AUsing a constant value
BUsing forward fill method
CUsing backward fill method
DUsing <code>dropna()</code> inside <code>fillna()</code>
Explain how you would handle missing values in a dataset using the fillna() function.
Think about replacing NaN with a value or copying nearby values.
You got /4 concepts.
    Describe the difference between using method='ffill' and filling with a constant value in fillna().
    Consider how missing data is replaced in each case.
    You got /3 concepts.