Pandas How to Convert Series to List with Example
.tolist() method, like my_series.tolist().Examples
How to Think About It
tolist() that does exactly this by extracting all values in order.Algorithm
Code
import pandas as pd my_series = pd.Series([10, 20, 30]) my_list = my_series.tolist() print(my_list)
Dry Run
Let's trace converting pd.Series([10, 20, 30]) to a list.
Create Series
my_series = pd.Series([10, 20, 30]) creates a Series with values 10, 20, 30.
Convert to list
Calling my_series.tolist() extracts values into a list [10, 20, 30].
Print list
Printing the list shows [10, 20, 30].
| Step | Series Values | List 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
import pandas as pd my_series = pd.Series([1, 2, 3]) my_list = list(my_series) print(my_list)
import pandas as pd my_series = pd.Series([1, 2, 3]) my_list = list(my_series.values) print(my_list)
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.
| Approach | Time | Space | Best 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 |
.tolist() for a clear and direct way to convert a Series to a list.list() on the Series index or other attributes instead of the Series itself.