0
0
Pandasdata~10 mins

Feature engineering basics 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 create a new column 'age_squared' by squaring the 'age' column.

Pandas
df['age_squared'] = df['age'] [1] 2
Drag options to blanks, or click blank then click option'
A**
B+
C*
D//
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+' instead of '**' will add 2 instead of squaring.
Using '*' will multiply by 2, not square.
2fill in blank
medium

Complete the code to create a new column 'is_adult' that is True if 'age' is 18 or more, else False.

Pandas
df['is_adult'] = df['age'] [1] 18
Drag options to blanks, or click blank then click option'
A<=
B>=
C==
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' will select ages less than or equal to 18, which is opposite.
Using '==' will only select age exactly 18.
3fill in blank
hard

Fix the error in the code to create a new column 'bmi' as weight divided by height squared.

Pandas
df['bmi'] = df['weight'] / (df['height'] [1] 2)
Drag options to blanks, or click blank then click option'
A+
B*
C**
D//
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' multiplies height by 2, not squares it.
Using '//' does integer division, which is incorrect here.
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 '<' will select words shorter than 3, opposite of requirement.
Using 'word' as value stores the word itself, not its length.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values only for items with positive values.

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()' keeps keys lowercase.
Using '<' or '<=' filters wrong items.