0
0
Pandasdata~10 mins

Creating Series from list and dictionary in Pandas - Visual Walkthrough

Choose your learning style9 modes available
Concept Flow - Creating Series from list and dictionary
Start with data: list or dict
Call pd.Series(data)
If list: create Series with default index
If dict: create Series with keys as index
Result: Series object with values and index
Done
We start with a list or dictionary, then call pandas Series constructor. If input is a list, Series gets default numeric index. If input is a dictionary, Series uses keys as index.
Execution Sample
Pandas
import pandas as pd

lst = [10, 20, 30]
ser_list = pd.Series(lst)

dict_data = {'a': 100, 'b': 200}
ser_dict = pd.Series(dict_data)
Create two Series: one from a list with default index, one from a dictionary with keys as index.
Execution Table
StepInput TypeInput DataActionOutput Series (values and index)
1list[10, 20, 30]Call pd.Series(lst)0:10, 1:20, 2:30
2dict{'a': 100, 'b': 200}Call pd.Series(dict_data)a:100, b:200
3--End of creationSeries objects ready
💡 All inputs converted to Series; list uses default numeric index, dict uses keys as index.
Variable Tracker
VariableStartAfter Step 1After Step 2Final
lst[10, 20, 30][10, 20, 30][10, 20, 30][10, 20, 30]
ser_listnullSeries(values=[10, 20, 30], index=[0, 1, 2])Series(values=[10, 20, 30], index=[0, 1, 2])Series(values=[10, 20, 30], index=[0, 1, 2])
dict_data{'a': 100, 'b': 200}{'a': 100, 'b': 200}{'a': 100, 'b': 200}{'a': 100, 'b': 200}
ser_dictnullnullSeries(values=[100, 200], index=['a', 'b'])Series(values=[100, 200], index=['a', 'b'])
Key Moments - 3 Insights
Why does the Series created from a list have numeric index starting at 0?
Because when you create a Series from a list, pandas automatically assigns a default integer index starting from 0, as shown in execution_table step 1.
Why does the Series created from a dictionary use the dictionary keys as the index?
When creating a Series from a dictionary, pandas uses the dictionary keys as the index labels, as seen in execution_table step 2.
Can the index be customized when creating a Series from a list or dictionary?
Yes, you can pass an index parameter to pd.Series to set custom index labels, but in this example default behavior is shown.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table row 1. What is the index of the Series created from the list?
A[10, 20, 30]
B['a', 'b', 'c']
C[0, 1, 2]
D['x', 'y', 'z']
💡 Hint
Check the 'Output Series' column in execution_table row 1 for index values.
According to variable_tracker, what is the value of ser_dict after step 2?
ASeries with values [10, 20, 30] and index [0,1,2]
BSeries with values [100, 200] and index ['a', 'b']
Cnull
DDictionary {'a': 100, 'b': 200}
💡 Hint
Look at the 'ser_dict' row and 'After Step 2' column in variable_tracker.
If we create a Series from a dictionary with keys ['x', 'y'], what will be the index?
A['x', 'y']
B[0, 1]
C['a', 'b']
DDefault numeric index starting at 0
💡 Hint
Refer to the concept_flow and execution_table step 2 where dictionary keys become index.
Concept Snapshot
pd.Series(data) creates a Series from list or dict.
- From list: values get default numeric index starting at 0.
- From dict: keys become index labels.
- Result is a one-dimensional labeled array.
- Index can be customized with index= parameter.
Full Transcript
This visual execution shows how to create pandas Series from a list and a dictionary. Starting with a list of numbers, calling pd.Series creates a Series with default numeric index 0,1,2. Starting with a dictionary, pd.Series uses the dictionary keys as the index labels. The execution table traces each step, showing input type, data, action, and resulting Series values and index. The variable tracker shows how variables change after each step. Key moments clarify why list-based Series have numeric index and dictionary-based Series use keys as index. The visual quiz tests understanding of index assignment and variable states. The concept snapshot summarizes the syntax and behavior for quick reference.