A pandas Series is like a single column of data with labels (called an index). It can hold numbers, words, or other data types.
Click to reveal answer
beginner
How do you create a Series from a list in pandas?
Use pd.Series(your_list). The list values become the data, and pandas automatically creates index numbers starting at 0.
Click to reveal answer
beginner
How does pandas create a Series from a dictionary?
When you pass a dictionary to pd.Series(), the dictionary keys become the index labels, and the values become the data.
Click to reveal answer
intermediate
Can you assign custom index labels when creating a Series from a list?
Yes! Use the index parameter like pd.Series(data, index=[labels]) to set your own labels instead of default numbers.
Click to reveal answer
intermediate
What happens if you create a Series from a dict but specify an index with labels not in the dict?
Pandas will create entries for those labels with NaN (missing) values because the dict has no data for them.
Click to reveal answer
What does pd.Series([10, 20, 30]) produce?
AA Series with values 10, 20, 30 and index 0, 1, 2
BA Series with index 10, 20, 30 and values 0, 1, 2
CA DataFrame with 3 columns
DAn error because list is not allowed
✗ Incorrect
Passing a list creates a Series with the list values as data and default numeric index starting at 0.
If you create a Series from a dict {'a': 1, 'b': 2}, what will be the index?
A['a', 'b']
B['b', 'a']
C[1, 2]
D[0, 1]
✗ Incorrect
The dict keys become the Series index labels.
How can you create a Series from a list with custom labels 'x', 'y', 'z'?
Apd.Series(data, labels=['x', 'y', 'z'])
Bpd.Series(data).labels(['x', 'y', 'z'])
Cpd.Series(data, index=['x', 'y', 'z'])
Dpd.Series(data).index(['x', 'y', 'z'])
✗ Incorrect
Use the index parameter to assign custom labels.
What value does pandas assign if an index label is not found in the dictionary when creating a Series?
ARaises an error
B0
CEmpty string
DNaN
✗ Incorrect
Pandas uses NaN to represent missing data.
Which of these is a valid way to create a Series from a dictionary?
Apd.Series(1, 2, 3)
Bpd.Series({'a': 1, 'b': 2})
Cpd.Series(['a', 'b'], [1, 2])
Dpd.Series('a':1, 'b':2)
✗ Incorrect
Passing a dictionary directly to pd.Series creates a Series with keys as index and values as data.
Explain how to create a pandas Series from a list and how to add custom index labels.
Think about the parameters of pd.Series()
You got /4 concepts.
Describe what happens when you create a Series from a dictionary and specify an index with labels not in the dictionary.
Consider how pandas handles missing data
You got /4 concepts.
Practice
(1/5)
1. What does a pandas Series store besides the data itself?
easy
A. Multiple columns like a DataFrame
B. Labels (index) for each data element
C. Only numeric values
D. No labels, just raw data
Solution
Step 1: Understand what a Series is
A Series is like a list but with labels for each element.
Step 2: Identify what is stored besides data
Besides the data values, a Series stores labels called an index.
Final Answer:
Labels (index) for each data element -> Option B
Quick Check:
Series stores data + labels [OK]
Hint: Remember: Series = data + labels (index) [OK]
Common Mistakes:
Thinking Series stores multiple columns like DataFrame
Assuming Series only stores numeric data
Believing Series has no labels
2. Which of the following is the correct way to create a pandas Series from a list [10, 20, 30] with labels ['a', 'b', 'c']?
easy
A. pd.Series([10, 20, 30], labels=['a', 'b', 'c'])
B. pd.Series(index=[10, 20, 30], data=['a', 'b', 'c'])
C. pd.Series({'a':10, 'b':20, 'c':30})
D. pd.Series([10, 20, 30], index=['a', 'b', 'c'])
Solution
Step 1: Recall Series creation syntax from list
Use pd.Series(data_list, index=labels_list) to assign labels.
Step 2: Check each option
pd.Series([10, 20, 30], index=['a', 'b', 'c']) uses correct syntax: data first, then index labels. Others misuse parameters or use wrong keywords.
Final Answer:
pd.Series([10, 20, 30], index=['a', 'b', 'c']) -> Option D
Quick Check:
Correct syntax uses index= for labels [OK]
Hint: Use index= to assign labels when creating Series from list [OK]
Common Mistakes:
Using labels= instead of index=
Swapping data and index parameters
Passing dict instead of list for this question
3. What will be the output of this code?
import pandas as pd
s = pd.Series({'x': 5, 'y': 10, 'z': 15})
print(s['y'])
medium
A. 10
B. 'y'
C. KeyError
D. 5
Solution
Step 1: Understand Series creation from dict
Keys become labels, values become data. So 'y' label has value 10.
Step 2: Access value by label 'y'
Using s['y'] returns the value 10 stored at label 'y'.
Final Answer:
10 -> Option A
Quick Check:
Dict keys = labels, s['y'] = 10 [OK]
Hint: Dict keys become labels; access by label returns value [OK]
Common Mistakes:
Expecting s['y'] to return the label 'y'
Confusing keys and values
Thinking it raises KeyError
4. Identify the error in this code snippet:
import pandas as pd
s = pd.Series([1, 2, 3], index=['a', 'b'])
medium
A. No error, code runs fine
B. Data must be a dictionary, not a list
C. Index length does not match data length
D. pd.Series cannot take index parameter
Solution
Step 1: Check lengths of data and index
Data has 3 elements, index has 2 labels. They must be equal length.
Step 2: Understand pandas behavior
Mismatch causes ValueError: Length of passed values does not match index.
Final Answer:
Index length does not match data length -> Option C
Quick Check:
Data and index lengths must match [OK]
Hint: Data and index must have same length [OK]
Common Mistakes:
Assuming list data must be dict
Thinking index parameter is invalid
Ignoring length mismatch error
5. You have a dictionary {'a': 1, 'b': 0, 'c': 3, 'd': None}. You want to create a Series that only includes keys with truthy values (non-zero, non-None). Which code correctly creates this filtered Series?
hard
A. pd.Series({k: v for k, v in {'a':1, 'b':0, 'c':3, 'd':None}.items() if v})
B. pd.Series({'a':1, 'b':0, 'c':3, 'd':None}).dropna()
C. pd.Series({'a':1, 'b':0, 'c':3, 'd':None}).fillna(0)
D. pd.Series({'a':1, 'b':0, 'c':3, 'd':None})
Solution
Step 1: Understand filtering for truthy values
Truthy means values that are not 0, None, False, or empty.
Step 2: Check each option's effect
pd.Series({k: v for k, v in {'a':1, 'b':0, 'c':3, 'd':None}.items() if v}) uses dict comprehension to filter out falsy values before creating Series. pd.Series({'a':1, 'b':0, 'c':3, 'd':None}).dropna() only drops None but keeps 0. pd.Series({'a':1, 'b':0, 'c':3, 'd':None}).fillna(0) replaces None with 0, keeping falsy values. pd.Series({'a':1, 'b':0, 'c':3, 'd':None}) includes all values.
Final Answer:
pd.Series({k: v for k, v in {'a':1, 'b':0, 'c':3, 'd':None}.items() if v}) -> Option A
Quick Check:
Filter dict first to exclude falsy values [OK]
Hint: Filter dict with if v before Series creation [OK]
Common Mistakes:
Using dropna() only removes None, not 0
Filling None with 0 keeps falsy values
Not filtering before creating Series
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.