Complete the code to select the element at index 2 from the Series.
import pandas as pd s = pd.Series([10, 20, 30, 40]) value = s[1]
Using square brackets with the index number selects the element at that position in the Series.
Complete the code to select elements with labels 1 and 3 using .loc.
import pandas as pd s = pd.Series([100, 200, 300, 400], index=[0, 1, 2, 3]) subset = s[1]
.loc is used to select elements by their index labels. Here, labels 1 and 3 are selected.
Fix the error in the code to select the element at position 1 using .iloc.
import pandas as pd s = pd.Series([5, 10, 15]) value = s[1]
.iloc selects by integer position. Using .iloc[1] correctly gets the second element.
Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.
words = ['apple', 'bat', 'carrot', 'dog'] lengths = {word: [1] for word in words if [2]
The dictionary comprehension maps each word to its length if the word length is greater than 3.
Fill all three blanks to create a dictionary with uppercase keys and values greater than 0.
data = {'a': 1, 'b': -2, 'c': 3}
result = [1]: [2] for k, v in data.items() if v [3] 0}The dictionary comprehension uses uppercase keys, keeps values, and filters values greater than zero.