0
0
Pandasdata~10 mins

drop_duplicates() for removal 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 duplicate rows from the DataFrame df.

Pandas
df_clean = df.[1]()
Drag options to blanks, or click blank then click option'
Adrop_duplicates
Bsort_values
Cfillna
Ddropna
Attempts:
3 left
💡 Hint
Common Mistakes
Using dropna() which removes missing values, not duplicates.
Using fillna() which fills missing values.
Using sort_values() which sorts rows but does not remove duplicates.
2fill in blank
medium

Complete the code to remove duplicates based only on the 'Name' column.

Pandas
df_unique = df.drop_duplicates(subset=[1])
Drag options to blanks, or click blank then click option'
A'City'
B'Salary'
C'Name'
D'Age'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a column unrelated to duplicates like 'Age' or 'City'.
Not passing the column name as a string.
3fill in blank
hard

Fix the error in the code to remove duplicates and keep the last occurrence.

Pandas
df_last = df.drop_duplicates(keep=[1])
Drag options to blanks, or click blank then click option'
A'first'
B'last'
C'none'
D'all'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'first' which keeps the first occurrence instead.
Using invalid options like 'none' or 'all'.
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.

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

Fill all three blanks to create a dictionary of uppercase keys and values greater than zero.

Pandas
result = [1]: [2] for k, v in data.items() if v [3] 0}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using original keys without uppercase.
Using wrong comparison operators like '<'.