Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a DataFrame from a dictionary.
Data Analysis Python
import pandas as pd data = {'Name': ['Alice', 'Bob'], 'Age': [25, 30]} df = pd.[1](data) print(df)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pd.Series instead of pd.DataFrame
Trying to use list or array which are not pandas constructors
✗ Incorrect
Use pd.DataFrame() to create a DataFrame from a dictionary.
2fill in blank
mediumComplete the code to select the 'Age' column from the DataFrame.
Data Analysis Python
ages = df[1] print(ages)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using double square brackets returns a DataFrame, not a Series
Using dot notation with parentheses is invalid
✗ Incorrect
Use df['Age'] to select a single column as a Series.
3fill in blank
hardFix the error in the code to filter rows where Age is greater than 25.
Data Analysis Python
filtered = df[df['Age'] [1] 25] print(filtered)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using equality operator instead of greater than
Using less than or less than or equal operators
✗ Incorrect
Use > to filter rows where Age is greater than 25.
4fill in blank
hardFill both blanks to create a dictionary comprehension that maps words to their lengths for words longer than 3 letters.
Data Analysis Python
words = ['data', 'science', 'is', 'fun'] lengths = {word: [1] for word in words if [2] print(lengths)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Comparing the word string directly to a number
Using the word itself as the value instead of its length
✗ Incorrect
Use len(word) to get length and filter words with length greater than 3.
5fill in blank
hardFill all three blanks to create a dictionary with uppercase keys and values filtered by value > 20.
Data Analysis Python
data = {'a': 10, 'b': 25, 'c': 30}
result = { [1]: [2] for k, v in data.items() if v [3] 20 }
print(result) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase keys instead of uppercase
Filtering with wrong comparison operator
Swapping keys and values
✗ Incorrect
Keys are uppercase using k.upper(), values are v, filtered by v > 20.