0
0
Pandasdata~10 mins

apply() on columns 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 a function to each element in the 'age' column.

Pandas
df['age'] = df['age'].[1](lambda x: x + 1)
Drag options to blanks, or click blank then click option'
Areduce
Bmap
Cfilter
Dapply
Attempts:
3 left
💡 Hint
Common Mistakes
Using map instead of apply, which works differently on Series.
Using filter, which is for filtering elements, not transforming.
2fill in blank
medium

Complete the code to apply a function to each column in the DataFrame.

Pandas
result = df.[1](sum)
Drag options to blanks, or click blank then click option'
Aapplymap
Breduce
Capply
Dmap
Attempts:
3 left
💡 Hint
Common Mistakes
Using applymap, which applies element-wise, not column-wise.
Using map, which is not a DataFrame method.
3fill in blank
hard

Fix the error in applying a function to each column to get the max value.

Pandas
max_values = df.[1](max)
Drag options to blanks, or click blank then click option'
Afilter
Bapply
Cmap
Dapplymap
Attempts:
3 left
💡 Hint
Common Mistakes
Using applymap which causes an error here.
Using map which is not a DataFrame method.
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 value instead of its length.
Using less than instead of greater than in the condition.
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase words and their lengths for words longer than 4 characters.

Pandas
result = {{ [1]: [2] for word in words if len(word) [3] 4 }}
Drag options to blanks, or click blank then click option'
Aword.upper()
Blen(word)
C>
Dword
Attempts:
3 left
💡 Hint
Common Mistakes
Using the original word as key instead of uppercase.
Using less than or equal instead of greater than.