0
0
Data Analysis Pythondata~10 mins

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

Data Analysis Python
df['age'] = df['age'].[1](int)
Drag options to blanks, or click blank then click option'
Aastype
Bconvert
Cchange_type
Dto_int
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-existent method like 'convert' or 'to_int'.
Trying to assign the type directly without a method.
2fill in blank
medium

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

Data Analysis Python
df['price'] = df['price'].[1](float)
Drag options to blanks, or click blank then click option'
Aconvert
Bastype
Cto_float
Dchange_type
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'to_float' which is not a pandas method.
Trying to convert without using a method.
3fill in blank
hard

Fix the error in the code to convert the 'date' column to string type.

Data Analysis Python
df['date'] = df['date'].[1](str)
Drag options to blanks, or click blank then click option'
Achange_type
Bconvert
Cto_string
Dastype
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'to_string' which is not a pandas method for type conversion.
Using 'convert' or 'change_type' which do not exist.
4fill in blank
hard

Fill both blanks to convert the 'score' column to float and then to string.

Data Analysis Python
df['score'] = df['score'].[1](float).[2](str)
Drag options to blanks, or click blank then click option'
Aastype
Bconvert
Cto_string
Dchange_type
Attempts:
3 left
💡 Hint
Common Mistakes
Using different methods for each conversion.
Using non-existent methods like 'convert' or 'to_string'.
5fill in blank
hard

Fill all three blanks to create a new column 'age_str' by converting 'age' to string after converting to float.

Data Analysis Python
df['age_str'] = df['age'].[1](int).[2](float).[3](str)
Drag options to blanks, or click blank then click option'
Aastype
Bconvert
Cto_string
Dchange_type
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing different methods for conversion.
Using methods that do not exist in pandas.