0
0
Data Analysis Pythondata~10 mins

Removing duplicates (drop_duplicates) in Data Analysis Python - 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.

Data Analysis Python
df_unique = df.[1]()
Drag options to blanks, or click blank then click option'
Asort_values
Bdropna
Cfillna
Ddrop_duplicates
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 data but does not remove duplicates.
2fill in blank
medium

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

Data Analysis Python
df_unique = df.drop_duplicates(subset=[1])
Drag options to blanks, or click blank then click option'
A['City']
B['Name']
C['Salary']
D['Age']
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a column unrelated to duplicates.
Not using a list for the subset parameter.
3fill in blank
hard

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

Data Analysis Python
df_unique = df.drop_duplicates(keep=[1])
Drag options to blanks, or click blank then click option'
A'last'
B'none'
C'first'
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 remove duplicates based on 'City' and keep only the first occurrence.

Data Analysis Python
df_unique = df.drop_duplicates(subset=[1], keep=[2])
Drag options to blanks, or click blank then click option'
A['City']
B'first'
C'last'
D['Name']
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong column for subset.
Using 'last' instead of 'first' for keep.
5fill in blank
hard

Fill all three blanks to create a dictionary with names as keys and ages as values, only for unique names.

Data Analysis Python
unique_ages = { [3].[1]: [3].[2] for [3] in df.drop_duplicates(subset=['Name']).itertuples() }
Drag options to blanks, or click blank then click option'
AName
BAge
Crow
Ddf
Attempts:
3 left
💡 Hint
Common Mistakes
Using the DataFrame name 'df' as loop variable.
Swapping keys and values in the dictionary.
Not using the correct loop variable.