Challenge - 5 Problems
Fill Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of forward fill on missing data?
Given the following pandas DataFrame with missing values, what will be the result after applying forward fill (ffill)?
Data Analysis Python
import pandas as pd df = pd.DataFrame({'A': [1, None, None, 4, None, 6]}) result = df.ffill() print(result)
Attempts:
2 left
💡 Hint
Forward fill replaces missing values with the last known non-missing value above it.
✗ Incorrect
Forward fill (ffill) fills missing values by propagating the last valid observation forward. So, missing values after 1.0 become 1.0 until a new non-missing value appears.
❓ Predict Output
intermediate2:00remaining
What is the output of backward fill on missing data?
Given the following pandas DataFrame with missing values, what will be the result after applying backward fill (bfill)?
Data Analysis Python
import pandas as pd df = pd.DataFrame({'A': [1, None, None, 4, None, 6]}) result = df.bfill() print(result)
Attempts:
2 left
💡 Hint
Backward fill replaces missing values with the next known non-missing value below it.
✗ Incorrect
Backward fill (bfill) fills missing values by propagating the next valid observation backward. So, missing values before 4.0 become 4.0, and the missing value before 6.0 becomes 6.0.
❓ data_output
advanced2:00remaining
How many missing values remain after forward fill?
Given this DataFrame, how many missing values remain after applying forward fill on column 'B' only?
Data Analysis Python
import pandas as pd import numpy as np df = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [np.nan, 5, np.nan, 7]}) result = df.copy() result['B'] = result['B'].ffill() missing_count = result['B'].isna().sum() print(missing_count)
Attempts:
2 left
💡 Hint
Forward fill cannot fill missing values at the start if no previous value exists.
✗ Incorrect
The first value in column 'B' is NaN and has no previous value to fill from, so it remains NaN. The other NaN at index 2 is filled with 5. So, one missing value remains.
❓ visualization
advanced3:00remaining
Which plot shows the effect of backward fill on missing data?
You have a time series with missing values. Which plot correctly shows the data after applying backward fill?
Data Analysis Python
import pandas as pd import matplotlib.pyplot as plt import numpy as np dates = pd.date_range('2024-01-01', periods=6) values = [1, np.nan, np.nan, 4, np.nan, 6] df = pd.DataFrame({'Value': values}, index=dates) df_bfill = df.bfill() plt.figure(figsize=(8,4)) plt.plot(df.index, df['Value'], marker='o', label='Original') plt.plot(df_bfill.index, df_bfill['Value'], marker='x', label='Backward Fill') plt.legend() plt.title('Backward Fill Effect') plt.xlabel('Date') plt.ylabel('Value') plt.grid(True) plt.tight_layout() plt.show()
Attempts:
2 left
💡 Hint
Backward fill uses the next valid value to fill missing points, so the line jumps up at missing points.
✗ Incorrect
Backward fill replaces missing values with the next valid value, so the plot shows the line jumping up at missing points to the next known value.
🧠 Conceptual
expert2:30remaining
What is the difference between forward fill and backward fill in time series data?
Choose the best explanation of how forward fill and backward fill handle missing values differently in time series data.
Attempts:
2 left
💡 Hint
Think about the direction in which each fill method propagates values.
✗ Incorrect
Forward fill propagates the last valid observation forward to fill missing values. Backward fill propagates the next valid observation backward to fill missing values.