0
0
Pandasdata~10 mins

Keeping first vs last vs none in Pandas - Interactive Practice

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

Complete the code to drop duplicate rows keeping the first occurrence.

Pandas
df_unique = df.drop_duplicates(keep=[1])
Drag options to blanks, or click blank then click option'
ANone
B"first"
CFalse
D"last"
Attempts:
3 left
💡 Hint
Common Mistakes
Using keep=None causes an error.
Using keep=False drops all duplicates.
Using keep='last' keeps the last duplicates, not the first.
2fill in blank
medium

Complete the code to drop duplicate rows keeping the last occurrence.

Pandas
df_unique = df.drop_duplicates(keep=[1])
Drag options to blanks, or click blank then click option'
A"first"
BTrue
CNone
D"last"
Attempts:
3 left
💡 Hint
Common Mistakes
Using keep='first' keeps the first duplicates, not the last.
Using keep=None causes an error.
Using keep=True is invalid.
3fill in blank
hard

Fix the error in the code to drop all duplicates (keep none).

Pandas
df_unique = df.drop_duplicates(keep=[1])
Drag options to blanks, or click blank then click option'
A"first"
B"last"
CFalse
DNone
Attempts:
3 left
💡 Hint
Common Mistakes
Using keep=None causes an error.
Using keep='first' or 'last' keeps some duplicates.
Using keep=True is invalid.
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 '<' instead of '>' in the condition.
Using 'word' instead of 'len(word)' for the value.
Using 'word' in the condition instead of length.
5fill in blank
hard

Fill all three blanks to create a dictionary with 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 'k' instead of 'k.upper()' for keys.
Using '<' instead of '>' in the condition.
Using 'k' instead of 'v' for values.