0
0
Pandasdata~10 mins

Using appropriate dtypes 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'].astype([1])
Drag options to blanks, or click blank then click option'
A"bool"
B"float"
C"str"
D"int"
Attempts:
3 left
💡 Hint
Common Mistakes
Using "float" instead of "int" changes the type incorrectly.
Using "str" converts numbers to text.
2fill in blank
medium

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

Pandas
df['price'] = df['price'].astype([1])
Drag options to blanks, or click blank then click option'
A"float"
B"category"
C"int"
D"bool"
Attempts:
3 left
💡 Hint
Common Mistakes
Using "int" loses decimal information.
Using "category" is for categorical data, not numbers.
3fill in blank
hard

Fix the error in the code to convert the 'status' column to category type.

Pandas
df['status'] = df['status'].astype([1])
Drag options to blanks, or click blank then click option'
A"cat"
Bcategory
C"category"
Dcat
Attempts:
3 left
💡 Hint
Common Mistakes
Using category without quotes causes a NameError.
Using "cat" is not a valid dtype name.
4fill in blank
hard

Fill both blanks to create a dictionary that converts 'score' to float and 'passed' to bool.

Pandas
dtype_dict = {'score': [1], 'passed': [2]
Drag options to blanks, or click blank then click option'
A"float"
B"int"
C"bool"
D"str"
Attempts:
3 left
💡 Hint
Common Mistakes
Using "int" for score loses decimals.
Using "str" for passed is incorrect.
5fill in blank
hard

Fill in the blank to convert columns using a dtype dictionary: 'height' to float, 'weight' to int, and 'active' to bool.

Pandas
df = df.astype([1])
Drag options to blanks, or click blank then click option'
A{'height': 'float', 'weight': 'int', 'active': 'bool'}
B{'height': 'int', 'weight': 'float', 'active': 'bool'}
C{'height': 'float', 'weight': 'int', 'active': 'str'}
D{'height': 'bool', 'weight': 'int', 'active': 'float'}
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping float and int for height and weight.
Using 'str' for active instead of 'bool'.