0
0
Pandasdata~10 mins

Handling inconsistent values 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 replace all occurrences of 'N/A' with NaN in the DataFrame df.

Pandas
df = df.replace([1], np.nan)
Drag options to blanks, or click blank then click option'
A'None'
B'null'
C'missing'
D'N/A'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'None' or 'null' instead of 'N/A' which does not match the data.
Not using np.nan to represent missing values.
2fill in blank
medium

Complete the code to drop rows from df that contain any NaN values.

Pandas
df_clean = df.[1](axis=0)
Drag options to blanks, or click blank then click option'
Afillna
Bdropna
Cisnull
Dreplace
Attempts:
3 left
💡 Hint
Common Mistakes
Using fillna instead of dropna, which fills missing values instead of dropping rows.
Using isnull which only returns a boolean mask.
3fill in blank
hard

Fix the error in the code to convert the 'age' column to numeric, coercing errors to NaN.

Pandas
df['age'] = pd.to_numeric(df['age'], errors=[1])
Drag options to blanks, or click blank then click option'
A'coerce'
B'ignore'
C'raise'
D'convert'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'raise' which causes an error on invalid values.
Using 'ignore' which leaves invalid values unchanged.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.

Pandas
{word: [1] for word in words if [2] > 3}
Drag options to blanks, or click blank then click option'
Alen(word)
Bword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length.
Checking the word instead of its length in the condition.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase keys to values only if value is positive.

Pandas
{ [1]: [2] for [3], v in data.items() if v > 0 }
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
Ck
Dv.upper()
Attempts:
3 left
💡 Hint
Common Mistakes
Using the value as key or vice versa.
Not converting keys to uppercase.