0
0
Pandasdata~10 mins

Combining multiple cleaning steps 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 remove rows with missing values from the DataFrame.

Pandas
cleaned_df = df.[1]()
Drag options to blanks, or click blank then click option'
Aisnull
Bfillna
Creplace
Ddropna
Attempts:
3 left
💡 Hint
Common Mistakes
Using fillna() instead of dropna()
Using isnull() which only checks for missing values
2fill in blank
medium

Complete the code to convert the 'date' column to datetime format.

Pandas
df['date'] = pd.[1](df['date'])
Drag options to blanks, or click blank then click option'
Ato_numeric
Bto_datetime
Cto_string
Dto_timedelta
Attempts:
3 left
💡 Hint
Common Mistakes
Using to_numeric() which converts to numbers
Using to_timedelta() which is for time differences
3fill in blank
hard

Fix the error in the code to rename the column 'old_name' to 'new_name'.

Pandas
df = df.rename(columns=[1])
Drag options to blanks, or click blank then click option'
A{'old_name': 'new_name'}
B['old_name', 'new_name']
C('old_name', 'new_name')
D'old_name:new_name'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list or tuple instead of a dictionary
Using a string with colon instead of a dictionary
4fill in blank
hard

Fill both blanks to create a new column 'length' with the length of strings in 'name' column, but only for names longer than 3 characters.

Pandas
df['length'] = df['name'].apply(lambda x: [1] if len(x) [2] 3 else 0)
Drag options to blanks, or click blank then click option'
Alen(x)
B>
C<
Dx
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'x' instead of 'len(x)'
Using '<' instead of '>' in the condition
5fill in blank
hard

Fill all three blanks to create a dictionary with words as keys and their lengths as values, but only for words longer than 4 characters.

Pandas
lengths = { [1]: [2] for [3] in words if len([3]) > 4 }
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently
Using item instead of word