Bird
Raised Fist0
Data Analysis Pythondata~20 mins

Series creation from lists and dicts in Data Analysis Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Series Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of Series from list with custom index
What is the output of this code creating a pandas Series from a list with a custom index?
Data Analysis Python
import pandas as pd
s = pd.Series([10, 20, 30], index=['a', 'b', 'c'])
print(s)
A
a    10
b    20
c    30
dtype: object
B
0    10
1    20
2    30
dtype: int64
C
a    10
b    20
c    30
Name: None, dtype: int64
D
a    10
b    20
c    30
dtype: int64
Attempts:
2 left
💡 Hint
Check how the index parameter changes the labels of the Series.
❓ data_output
intermediate
1:30remaining
Length of Series from dict with missing keys
What is the length of the Series created from this dictionary with a specified index containing keys not in the dict?
Data Analysis Python
import pandas as pd
d = {'x': 1, 'y': 2}
s = pd.Series(d, index=['x', 'y', 'z'])
print(len(s))
A2
B3
CKeyError
D1
Attempts:
2 left
💡 Hint
Series length matches the index length, even if some keys are missing in the dict.
🔧 Debug
advanced
2:00remaining
Identify the error in Series creation from dict with list values
What error does this code raise when creating a Series from a dictionary with list values?
Data Analysis Python
import pandas as pd
d = {'a': [1, 2], 'b': [3, 4]}
s = pd.Series(d)
print(s)
ANo error, prints the Series with lists as values
BValueError: arrays must be same length
CTypeError: unhashable type: 'list'
DKeyError: 'a'
Attempts:
2 left
💡 Hint
Check if pandas allows lists as values in Series from dict.
🧠 Conceptual
advanced
1:30remaining
Behavior of Series creation from dict with partial index
When creating a pandas Series from a dictionary with a specified index that includes keys not in the dictionary, what value does pandas assign to those missing keys?
AIt assigns NaN (Not a Number) to missing keys in the Series.
BIt raises a KeyError and stops execution.
CIt assigns zero (0) to missing keys automatically.
DIt ignores missing keys and creates Series only with existing keys.
Attempts:
2 left
💡 Hint
Think about how pandas handles missing data in Series.
🚀 Application
expert
2:00remaining
Create Series from dict with mixed types and analyze output
Given this dictionary with mixed value types, what is the dtype of the resulting Series?
Data Analysis Python
import pandas as pd
d = {'a': 1, 'b': 2.5, 'c': '3'}
s = pd.Series(d)
print(s.dtype)
Aint64
Bfloat64
Cobject
Dstring
Attempts:
2 left
💡 Hint
Consider how pandas handles mixed data types in a Series.

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

  1. Step 1: Understand what a Series is

    A Series is like a list but with labels for each element.
  2. Step 2: Identify what is stored besides data

    Besides the data values, a Series stores labels called an index.
  3. Final Answer:

    Labels (index) for each data element -> Option B
  4. 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

  1. Step 1: Recall Series creation syntax from list

    Use pd.Series(data_list, index=labels_list) to assign labels.
  2. 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.
  3. Final Answer:

    pd.Series([10, 20, 30], index=['a', 'b', 'c']) -> Option D
  4. 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

  1. Step 1: Understand Series creation from dict

    Keys become labels, values become data. So 'y' label has value 10.
  2. Step 2: Access value by label 'y'

    Using s['y'] returns the value 10 stored at label 'y'.
  3. Final Answer:

    10 -> Option A
  4. 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

  1. Step 1: Check lengths of data and index

    Data has 3 elements, index has 2 labels. They must be equal length.
  2. Step 2: Understand pandas behavior

    Mismatch causes ValueError: Length of passed values does not match index.
  3. Final Answer:

    Index length does not match data length -> Option C
  4. 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

  1. Step 1: Understand filtering for truthy values

    Truthy means values that are not 0, None, False, or empty.
  2. 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.
  3. Final Answer:

    pd.Series({k: v for k, v in {'a':1, 'b':0, 'c':3, 'd':None}.items() if v}) -> Option A
  4. 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 unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard