0
0
Data Analysis Pythondata~10 mins

Why transformation reshapes data for analysis in Data Analysis Python - Test Your Understanding

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to reshape the data using pandas melt function.

Data Analysis Python
import pandas as pd

data = pd.DataFrame({
    'Name': ['Alice', 'Bob'],
    'Math': [90, 80],
    'Science': [85, 88]
})

reshaped = pd.melt(data, id_vars=['Name'], value_vars=[1])
print(reshaped)
Drag options to blanks, or click blank then click option'
A['Math', 'Science']
B['Name']
C['Math']
D['Science']
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Name' in value_vars instead of id_vars
Not passing a list for value_vars
2fill in blank
medium

Complete the code to pivot the reshaped data back to wide format.

Data Analysis Python
reshaped.pivot(index='Name', columns=[1], values='value')
Drag options to blanks, or click blank then click option'
A'score'
B'Name'
C'variable'
D'value'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Name' or 'value' as columns parameter
Confusing index and columns parameters
3fill in blank
hard

Fix the error in the code to correctly filter rows where score is greater than 85.

Data Analysis Python
filtered = reshaped[reshaped['value'] [1] 85]
print(filtered)
Drag options to blanks, or click blank then click option'
A>
B<
C==
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' or '<=' instead of '>'
Using '==' which checks for equality
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each word to its length if length is greater than 3.

Data Analysis Python
words = ['data', 'is', 'fun', 'science']
lengths = {word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Blen(word) > 3
Cword
Dword > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself as the value instead of its length
Using the word in the condition instead of its length
5fill in blank
hard

Fill all three blanks to create a dictionary from data items where the value is greater than 50, with keys uppercased.

Data Analysis Python
data = {'a': 40, 'b': 60, 'c': 70}
result = [1]: [2] for k, v in data.items() if v [3] 50}}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using original keys without uppercasing
Using wrong comparison operator
Swapping keys and values