0
0
Data Analysis Pythondata~10 mins

apply() function for custom logic 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 apply a function that doubles each value in the 'score' column.

Data Analysis Python
df['double_score'] = df['score'].[1](lambda x: x * 2)
Drag options to blanks, or click blank then click option'
Agroupby
Bmap
Cfilter
Dapply
Attempts:
3 left
💡 Hint
Common Mistakes
Using map instead of apply, which works differently on Series.
Trying to use filter which is for filtering rows, not transforming values.
2fill in blank
medium

Complete the code to apply a function that returns 'Pass' if score is 50 or more, else 'Fail'.

Data Analysis Python
df['result'] = df['score'].[1](lambda x: 'Pass' if x >= 50 else 'Fail')
Drag options to blanks, or click blank then click option'
Aapply
Bsort_values
Cgroupby
Dfilter
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter which is for filtering rows, not transforming values.
Trying to use groupby which is for grouping data, not element-wise operations.
3fill in blank
hard

Fix the error in applying a function that adds 10 to each value in the 'score' column.

Data Analysis Python
df['new_score'] = df['score'].[1](lambda x: x + 10)
Drag options to blanks, or click blank then click option'
Amap
Bfilter
Capply
Dreduce
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter which filters rows instead of transforming values.
Using reduce which aggregates values instead of element-wise operation.
4fill in blank
hard

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

Data Analysis Python
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.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values only if value is positive.

Data Analysis Python
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 key instead of uppercase key.
Using <= or < instead of > for filtering positive values.