0
0
Data Analysis Pythondata~10 mins

Series indexing and selection in Data Analysis Python - Interactive Code Practice

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

Complete the code to select the element at index 2 from the Series.

Data Analysis Python
import pandas as pd
s = pd.Series([10, 20, 30, 40])
value = s[1]
Drag options to blanks, or click blank then click option'
A[2]
B.loc[2]
C.iloc[2]
D[3]
Attempts:
3 left
💡 Hint
Common Mistakes
Using .loc instead of square brackets for positional selection
Using the wrong index number
2fill in blank
medium

Complete the code to select elements with labels 1 and 3 using .loc.

Data Analysis Python
import pandas as pd
s = pd.Series([100, 200, 300, 400], index=[0, 1, 2, 3])
subset = s[1]
Drag options to blanks, or click blank then click option'
A[[1, 3]]
B.loc[[1, 3]]
C.iloc[[1, 3]]
D[1, 3]
Attempts:
3 left
💡 Hint
Common Mistakes
Using .iloc instead of .loc for label-based selection
Not using double brackets for list selection
3fill in blank
hard

Fix the error in the code to select the element at position 1 using .iloc.

Data Analysis Python
import pandas as pd
s = pd.Series([5, 10, 15])
value = s[1]
Drag options to blanks, or click blank then click option'
A.iloc[1]
B.loc[1]
C[1]
D[[1]]
Attempts:
3 left
💡 Hint
Common Mistakes
Using .loc instead of .iloc for position selection
Using double brackets which returns a Series instead of a scalar
4fill in blank
hard

Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.

Data Analysis Python
words = ['apple', 'bat', 'carrot', 'dog']
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
Dlen(word) < 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself instead of its length
Using the wrong condition for filtering
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values greater than 0.

Data Analysis Python
data = {'a': 1, 'b': -2, 'c': 3}
result = [1]: [2] for k, v in data.items() if v [3] 0}
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
C>
Dk.lower()
Attempts:
3 left
💡 Hint
Common Mistakes
Using k.lower() instead of k.upper()
Using '<' instead of '>' in the condition
Using keys or values incorrectly in the comprehension