0
0
Pandasdata~10 mins

Missing data strategies decision in Pandas - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check for missing values in the DataFrame.

Pandas
missing_counts = df.isnull().[1]()
Drag options to blanks, or click blank then click option'
Asum
Bcount
Cmean
Dfillna
Attempts:
3 left
💡 Hint
Common Mistakes
Using count() which counts non-missing values instead of missing ones.
Using fillna() which replaces missing values instead of counting them.
2fill in blank
medium

Complete the code to drop rows with any missing values.

Pandas
clean_df = df.[1](axis=0, how='any')
Drag options to blanks, or click blank then click option'
Afillna
Breplace
Cisnull
Ddropna
Attempts:
3 left
💡 Hint
Common Mistakes
Using fillna() which fills missing values instead of dropping rows.
Using isnull() which only detects missing values but does not remove them.
3fill in blank
hard

Fix the error in the code to fill missing values with the column mean.

Pandas
df_filled = df.fillna(df.[1]())
Drag options to blanks, or click blank then click option'
Amean
Bmode
Cmedian
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using median() or mode() which are different statistics.
Using sum() which adds values but does not calculate average.
4fill in blank
hard

Fill both blanks to create a dictionary for filling missing values: fill numeric columns with mean and categorical with 'Unknown'.

Pandas
fill_values = {col: (df[col].[1]() if df[col].dtype == 'float64' else [2]) for col in df.columns}
Drag options to blanks, or click blank then click option'
Amean
B'Unknown'
C'NaN'
Dmedian
Attempts:
3 left
💡 Hint
Common Mistakes
Using median() instead of mean() for numeric columns.
Using 'NaN' string instead of 'Unknown' for categorical columns.
5fill in blank
hard

Fill all three blanks to create a new DataFrame with missing values filled: numeric columns with median, categorical with mode, and others with 'Missing'.

Pandas
fill_map = {col: (df[col].[1]() if df[col].dtype == 'float64' else (df[col].[2]()[0] if df[col].dtype == 'object' else [3])) for col in df.columns}
df_filled = df.fillna(fill_map)
Drag options to blanks, or click blank then click option'
Amedian
Bmode
C'Missing'
Dmean
Attempts:
3 left
💡 Hint
Common Mistakes
Using mean() instead of median() for numeric columns.
Not selecting the first mode value with [0].
Using 'Unknown' instead of 'Missing' for other types.