0
0
Pandasdata~10 mins

Series as labeled one-dimensional array in Pandas - Interactive Code Practice

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

Complete the code to create a pandas Series from a list.

Pandas
import pandas as pd

s = pd.Series([1])
print(s)
Drag options to blanks, or click blank then click option'
A{10, 20, 30}
B[10, 20, 30]
C(10, 20, 30)
D'10, 20, 30'
Attempts:
3 left
💡 Hint
Common Mistakes
Using curly braces {} which create a set, not a list.
Using parentheses () which create a tuple, not a list.
Passing a string instead of a list.
2fill in blank
medium

Complete the code to create a Series with custom labels (index).

Pandas
import pandas as pd

s = pd.Series([1, 2, 3], index=[1])
print(s)
Drag options to blanks, or click blank then click option'
A[0, 1, 2]
B(1, 2, 3)
C['a', 'b', 'c']
D{'a', 'b', 'c'}
Attempts:
3 left
💡 Hint
Common Mistakes
Using a tuple or set instead of a list for the index.
Using numbers instead of strings for labels when strings are expected.
3fill in blank
hard

Fix the error in the code to access the value with label 'b' from the Series.

Pandas
import pandas as pd

s = pd.Series([10, 20, 30], index=['a', 'b', 'c'])
value = s[[1]]
print(value)
Drag options to blanks, or click blank then click option'
A'b'
B"b"
Cb
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using the label without quotes causing a NameError.
Using the position index instead of the label.
4fill in blank
hard

Fill both blanks to create a Series from a dictionary and print its index labels.

Pandas
import pandas as pd

data = [1]
s = pd.Series(data)
print(s.[2])
Drag options to blanks, or click blank then click option'
A{'x': 100, 'y': 200, 'z': 300}
B[100, 200, 300]
Cindex
Dkeys
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list instead of a dictionary for data.
Using keys instead of index to get labels.
5fill in blank
hard

Fill all three blanks to create a Series with custom labels, access a value by label, and print the values as a list.

Pandas
import pandas as pd

s = pd.Series([1], index=[2])
value = s[[3]]
print(list(s.values))
Drag options to blanks, or click blank then click option'
A[5, 10, 15]
B['one', 'two', 'three']
C'two'
D['a', 'b', 'c']
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching lengths of values and index.
Accessing by position instead of label.
Not converting values to a list before printing.