Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a pandas Series from a list.
Data Analysis Python
import pandas as pd data = [10, 20, 30] series = pd.[1](data) print(series)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using DataFrame instead of Series
Trying to use list or array which are not pandas objects
✗ Incorrect
The Series function creates a 1D labeled array in pandas.
2fill in blank
mediumComplete the code to access the first element of a Series.
Data Analysis Python
import pandas as pd s = pd.Series([5, 10, 15]) first_element = s.[1][0] print(first_element)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using loc which accesses by label
Using index which returns index labels, not values
✗ Incorrect
iloc is used to access elements by integer position in a Series.
3fill in blank
hardFix the error in the code to create a Series with custom index labels.
Data Analysis Python
import pandas as pd values = [100, 200, 300] labels = ['a', 'b', 'c'] s = pd.Series([1], index=[2]) print(s)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping values and labels in arguments
Passing labels as data
✗ Incorrect
The first argument is the data values, and the second is the index labels.
4fill in blank
hardFill both blanks to create a Series and filter values greater than 15.
Data Analysis Python
import pandas as pd s = pd.Series([10, 20, 30, 5]) filtered = s[s [1] [2]] print(filtered)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>'
Using wrong number for comparison
✗ Incorrect
Use the greater than operator and the number 15 to filter values.
5fill in blank
hardFill all three blanks to create a dictionary from a Series with values greater than 10 and keys as uppercase labels.
Data Analysis Python
import pandas as pd s = pd.Series([5, 15, 25], index=['x', 'y', 'z']) result = [1]([2].upper(): [3] for [2], [3] in s.items() if [3] > 10) print(result)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not converting keys to uppercase
Using wrong variable names in comprehension
✗ Incorrect
Create a dictionary with keys as uppercase labels and values filtered by >10.