0
0
Data Analysis Pythondata~20 mins

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

Choose your learning style9 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.