0
0
Pandasdata~10 mins

map() for element-wise transformation 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 apply the function to each element in the 'score' column using map().

Pandas
df['score'] = df['score'].[1](lambda x: x + 10)
Drag options to blanks, or click blank then click option'
Amap
Breduce
Cfilter
Dapply
Attempts:
3 left
💡 Hint
Common Mistakes
Using apply instead of map, which works differently on Series.
Using filter or reduce which are not suitable for element-wise transformation.
2fill in blank
medium

Complete the code to replace values in the 'grade' column using a mapping dictionary with map().

Pandas
grade_map = {'A': 4, 'B': 3, 'C': 2}
df['grade_num'] = df['grade'].[1](grade_map)
Drag options to blanks, or click blank then click option'
Amap
Bapply
Creplace
Dfilter
Attempts:
3 left
💡 Hint
Common Mistakes
Using replace instead of map, which also works but is different in behavior.
Using apply which does not directly accept a dictionary for mapping.
3fill in blank
hard

Fix the error in the code to correctly map values in the 'status' column using map().

Pandas
status_map = {1: 'Active', 0: 'Inactive'}
df['status_text'] = df['status'].[1](status_map)
Drag options to blanks, or click blank then click option'
Aapply
Bfilter
Creplace
Dmap
Attempts:
3 left
💡 Hint
Common Mistakes
Using apply which does not accept a dictionary directly.
Using filter which is not for mapping values.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps words to their lengths, then apply it with map().

Pandas
length_map = {word: [1] for word in words if len(word) [2] 3}
result = df['text'].map(length_map)
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 instead of its length in the dictionary values.
Using the wrong comparison operator in the condition.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension mapping uppercase words to their lengths, then apply it with map().

Pandas
length_map = [1]: [2] for word in words if word [3] word.upper()
result = df['text'].map(length_map)
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
C==
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using word.upper() as the key instead of the original word.
Using incorrect comparison operators.
Using the wrong value for the dictionary.