0
0
PandasHow-ToBeginner · 2 min read

Pandas How to Convert Series to List with Example

You can convert a pandas Series to a list by using the .tolist() method, like my_series.tolist().
📋

Examples

Inputpd.Series([1, 2, 3])
Output[1, 2, 3]
Inputpd.Series(['apple', 'banana', 'cherry'])
Output['apple', 'banana', 'cherry']
Inputpd.Series([])
Output[]
🧠

How to Think About It

To convert a pandas Series to a list, think of the Series as a column of data. You want to take all the values in that column and put them into a simple Python list. The Series has a built-in method called tolist() that does exactly this by extracting all values in order.
📐

Algorithm

1
Get the pandas Series object you want to convert.
2
Call the <code>tolist()</code> method on the Series.
3
Return the resulting Python list.
💻

Code

python
import pandas as pd

my_series = pd.Series([10, 20, 30])
my_list = my_series.tolist()
print(my_list)
Output
[10, 20, 30]
🔍

Dry Run

Let's trace converting pd.Series([10, 20, 30]) to a list.

1

Create Series

my_series = pd.Series([10, 20, 30]) creates a Series with values 10, 20, 30.

2

Convert to list

Calling my_series.tolist() extracts values into a list [10, 20, 30].

3

Print list

Printing the list shows [10, 20, 30].

StepSeries ValuesList Output
1[10, 20, 30]
2[10, 20, 30][10, 20, 30]
3[10, 20, 30]
💡

Why This Works

Step 1: Series holds data

A pandas Series stores data in a one-dimensional labeled array.

Step 2: tolist() extracts values

The tolist() method extracts all values from the Series into a plain Python list.

Step 3: Result is a list

The output is a standard Python list that can be used anywhere lists are accepted.

🔄

Alternative Approaches

Using list() constructor
python
import pandas as pd
my_series = pd.Series([1, 2, 3])
my_list = list(my_series)
print(my_list)
This also converts the Series to a list but is less explicit than using <code>tolist()</code>.
Using .values attribute with list()
python
import pandas as pd
my_series = pd.Series([1, 2, 3])
my_list = list(my_series.values)
print(my_list)
This converts the underlying numpy array to a list; similar result but slightly more indirect.

Complexity: O(n) time, O(n) space

Time Complexity

Converting a Series to a list requires visiting each element once, so it takes linear time proportional to the number of elements.

Space Complexity

A new list is created to hold all elements, so space used is proportional to the number of elements.

Which Approach is Fastest?

Using tolist() is optimized and clear; using list() on the Series or its values is similar but less explicit.

ApproachTimeSpaceBest For
Series.tolist()O(n)O(n)Clear, idiomatic conversion
list(Series)O(n)O(n)Quick conversion, less explicit
list(Series.values)O(n)O(n)Converts underlying array, slightly indirect
💡
Use .tolist() for a clear and direct way to convert a Series to a list.
⚠️
Trying to convert a Series to list by calling list() on the Series index or other attributes instead of the Series itself.