0
0
Data Analysis Pythondata~10 mins

Data type optimization 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 a smaller integer type.

Data Analysis Python
df['age'] = df['age'].astype([1])
Drag options to blanks, or click blank then click option'
A"int8"
B"int64"
C"float64"
D"object"
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing 'int64' which uses more memory than needed.
Using 'float64' which is unnecessary for integer data.
2fill in blank
medium

Complete the code to convert the 'category' column to a categorical data type.

Data Analysis Python
df['category'] = df['category'].[1]('category')
Drag options to blanks, or click blank then click option'
Aastype('category')
Bastype
Cto_numeric
Dastype('object')
Attempts:
3 left
💡 Hint
Common Mistakes
Using to_numeric which converts to numbers, not categories.
Calling astype('category') as a method without arguments.
3fill in blank
hard

Fix the error in the code to convert the 'score' column to float32.

Data Analysis Python
df['score'] = df['score'].astype([1])
Drag options to blanks, or click blank then click option'
A"float32"
B"float"
Cfloat32
Dfloat
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the type without quotes causing a NameError.
Using just float which defaults to 64-bit float.
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 < which filters shorter words.
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 greater than zero.

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 k instead of k.upper() for keys.
Using < instead of > in the condition.