Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a pandas Series from a list of numbers.
Pandas
import pandas as pd numbers = [10, 20, 30] series = pd.Series([1]) print(series)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing 'dict' or 'pd.DataFrame' instead of the list variable.
Passing the string 'list' instead of the variable.
✗ Incorrect
We pass the list 'numbers' directly to pd.Series to create a Series.
2fill in blank
mediumComplete the code to create a pandas Series from a dictionary with custom index labels.
Pandas
import pandas as pd scores = {'Alice': 85, 'Bob': 90, 'Carol': 78} series = pd.Series([1], index=['Bob', 'Carol', 'Alice']) print(series)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a list of keys instead of the dictionary.
Passing only the values without keys.
✗ Incorrect
We pass the dictionary 'scores' to pd.Series and specify a custom index order.
3fill in blank
hardFix the error in the code to create a Series from a list with custom index labels.
Pandas
import pandas as pd values = [100, 200, 300] series = pd.Series(values, index=[1]) print(series)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using an index list with fewer or more labels than data items.
Using numeric strings that don't match data length.
✗ Incorrect
The index length must match the data length. Here, 3 values need 3 index labels.
4fill in blank
hardFill both blanks to create a Series from a dictionary and select values greater than 80.
Pandas
import pandas as pd grades = {'Math': 75, 'Science': 88, 'English': 92} series = pd.Series([1]) high_scores = series[series [2] 80] print(high_scores)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong comparison operator like '<' or '[80]'.
Passing the wrong data type to pd.Series.
✗ Incorrect
We create the Series from 'grades' and filter values greater than 80 using '>'.
5fill in blank
hardFill all three blanks to create a Series from a list, assign custom index, and filter values less than 50.
Pandas
import pandas as pd values = [45, 60, 30, 80] series = pd.Series([1], index=[2]) filtered = series[series [3] 50] print(filtered)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using an index list with wrong length.
Using wrong comparison operator like '>' instead of '<'.
✗ Incorrect
We pass the list 'values', assign a matching index list, and filter values less than 50 using '<'.