Convert List to Series in pandas - Simple Guide
pandas.Series(your_list) to convert a list to a pandas Series, for example: import pandas as pd; s = pd.Series([1, 2, 3]).Examples
How to Think About It
Algorithm
Code
import pandas as pd my_list = [10, 20, 30] my_series = pd.Series(my_list) print(my_series)
Dry Run
Let's trace converting the list [10, 20, 30] to a pandas Series.
Input list
my_list = [10, 20, 30]
Create Series
my_series = pd.Series(my_list) creates a Series with values 10, 20, 30 and indexes 0, 1, 2
Print Series
Output shows index and values: 0 10 1 20 2 30 dtype: int64
| Index | Value |
|---|---|
| 0 | 10 |
| 1 | 20 |
| 2 | 30 |
Why This Works
Step 1: Series constructor
The pd.Series() function takes a list and converts it into a Series object with default integer indexes.
Step 2: Default indexing
If no index is provided, pandas assigns numeric indexes starting from 0 automatically.
Step 3: Data type inference
Pandas infers the data type of the Series elements based on the list content, like int64 for numbers or object for strings.
Alternative Approaches
import pandas as pd my_list = [10, 20, 30] my_series = pd.Series(my_list, index=['a', 'b', 'c']) print(my_series)
import pandas as pd my_list = [10, 20, 30] my_series = pd.Series(dict(enumerate(my_list))) print(my_series)
Complexity: O(n) time, O(n) space
Time Complexity
Creating a Series from a list requires iterating over all elements once, so it takes linear time proportional to the list size.
Space Complexity
The Series stores all elements, so it uses extra memory proportional to the list size.
Which Approach is Fastest?
Using pd.Series() directly is the fastest and simplest method compared to alternatives that add extra steps.
| Approach | Time | Space | Best For |
|---|---|---|---|
| pd.Series(list) | O(n) | O(n) | Simple and direct conversion |
| pd.Series(list, index=...) | O(n) | O(n) | Custom index labels |
| pd.Series(dict(enumerate(list))) | O(n) | O(n) | When needing dict conversion |
pd before converting lists to Series for cleaner code.Series causes errors when converting lists.