0
0
Pandasdata~5 mins

Forward fill and backward fill in Pandas - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is forward fill in pandas?
Forward fill is a method to fill missing values by copying the last known non-missing value forward until a new non-missing value appears.
Click to reveal answer
beginner
What does backward fill do in pandas?
Backward fill fills missing values by copying the next known non-missing value backward until a previous non-missing value appears.
Click to reveal answer
beginner
How do you apply forward fill on a pandas DataFrame column named 'A'?
Use df['A'].fillna(method='ffill') to fill missing values in column 'A' by forward filling.
Click to reveal answer
beginner
What is the difference between forward fill and backward fill?
Forward fill uses previous values to fill missing data, while backward fill uses future values to fill missing data.
Click to reveal answer
intermediate
Can forward fill and backward fill be used together?
Yes, you can first apply forward fill to fill missing values, then apply backward fill to fill any remaining missing values.
Click to reveal answer
Which pandas method fills missing values by copying the previous non-missing value?
Afillna(method='ffill')
Bfillna(method='bfill')
Cdropna()
Dinterpolate()
What does fillna(method='bfill') do?
AFills missing values with the previous value
BFills missing values with the next value
CDrops missing values
DReplaces missing values with zero
If a DataFrame has missing values at the start, which fill method will fill them?
ANeither
BForward fill
CBackward fill
DBoth
Which method can you use to fill missing values first forward then backward?
Afillna(method='ffill').fillna(method='bfill')
Bfillna(method='bfill').fillna(method='ffill')
Cdropna()
Dinterpolate()
What happens if you apply forward fill on a column with no previous non-missing values?
AThey get filled with zeros
BAn error occurs
CThey get filled with the next non-missing value
DMissing values remain unchanged
Explain how forward fill and backward fill work to handle missing data in pandas.
Think about filling missing spots by looking backward or forward in the data.
You got /4 concepts.
    Describe a situation where you would use both forward fill and backward fill together.
    Consider missing data at the beginning and middle of a dataset.
    You got /4 concepts.