0
0
PandasHow-ToBeginner · 2 min read

Convert List to Series in pandas - Simple Guide

Use 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

Input[10, 20, 30]
Output0 10 1 20 2 30 dtype: int64
Input['apple', 'banana', 'cherry']
Output0 apple 1 banana 2 cherry dtype: object
Input[]
OutputSeries([], dtype: float64)
🧠

How to Think About It

To convert a list to a pandas Series, think of a Series as a labeled list. You just need to pass your list to the Series constructor, and pandas will create a Series with default numeric indexes.
📐

Algorithm

1
Get the input list.
2
Import the pandas library.
3
Pass the list to the pandas.Series() constructor.
4
Return the created Series object.
💻

Code

python
import pandas as pd

my_list = [10, 20, 30]
my_series = pd.Series(my_list)
print(my_series)
Output
0 10 1 20 2 30 dtype: int64
🔍

Dry Run

Let's trace converting the list [10, 20, 30] to a pandas Series.

1

Input list

my_list = [10, 20, 30]

2

Create Series

my_series = pd.Series(my_list) creates a Series with values 10, 20, 30 and indexes 0, 1, 2

3

Print Series

Output shows index and values: 0 10 1 20 2 30 dtype: int64

IndexValue
010
120
230
💡

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

Using pd.Series with custom index
python
import pandas as pd
my_list = [10, 20, 30]
my_series = pd.Series(my_list, index=['a', 'b', 'c'])
print(my_series)
Allows assigning custom labels instead of default numeric indexes.
Using from_dict with enumerate
python
import pandas as pd
my_list = [10, 20, 30]
my_series = pd.Series(dict(enumerate(my_list)))
print(my_series)
Converts list to dict with indexes, then to Series; useful for custom processing.

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.

ApproachTimeSpaceBest 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
💡
Always import pandas as pd before converting lists to Series for cleaner code.
⚠️
Forgetting to import pandas or misspelling Series causes errors when converting lists.