0
0
Pandasdata~10 mins

astype() for type conversion 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 convert the 'age' column to integer type.

Pandas
df['age'] = df['age'].[1]('int')
Drag options to blanks, or click blank then click option'
Aconvert
Bchange_type
Cto_int
Dastype
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent method like 'convert' or 'to_int'.
Trying to assign a string directly without conversion.
2fill in blank
medium

Complete the code to convert the 'price' column to float type.

Pandas
df['price'] = df['price'].[1]('float')
Drag options to blanks, or click blank then click option'
Ato_float
Bchange_type
Castype
Dconvert
Attempts:
3 left
💡 Hint
Common Mistakes
Using methods that do not exist in pandas.
Passing the wrong type string.
3fill in blank
hard

Complete the code to convert the 'score' column to string type.

Pandas
df['score'] = df['score'].[1]('str')
Drag options to blanks, or click blank then click option'
Achange_type
Bastype
Cto_str
Dconvert
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the Python type str instead of the string 'str'.
Using a non-existent method.
4fill in blank
hard

Fill both blanks to create a new column 'is_adult' with boolean type based on 'age' >= 18.

Pandas
df['is_adult'] = (df['age'] [1] 18).[2]('bool')
Drag options to blanks, or click blank then click option'
A>=
Bastype
C<
Dconvert
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong comparison operators like '<'.
Using a non-existent method for type conversion.
5fill in blank
hard

Fill both blanks to create a dictionary with 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'
A:
Blen(word)
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong dictionary syntax.
Using '<' instead of '>' for filtering.