Skip to main content

Python Pandas: How to Convert a Pandas Series to a Python List

Converting a pandas Series to a Python list is a common operation when you need to pass data to functions that expect standard Python types, serialize data for APIs, or simply work with list-based operations. The tolist() method provides a clean and efficient way to make this conversion.

In this guide, you'll learn how to convert a pandas Series to a list using tolist(), handle different data types, and understand when this conversion is useful.

Using tolist() to Convert a Series

The tolist() method converts a pandas Series into a standard Python list. It works with any data type - integers, floats, strings, or mixed types.

Converting a Numeric Series

import pandas as pd

numbers = pd.Series([2, 4, 6, 8, 10])

print("Pandas Series:")
print(numbers)
print(f"Type: {type(numbers)}")

# Convert to Python list
numbers_list = numbers.tolist()

print("\nPython list:")
print(numbers_list)
print(f"Type: {type(numbers_list)}")

Output:

Pandas Series:
0 2
1 4
2 6
3 8
4 10
dtype: int64
Type: <class 'pandas.core.series.Series'>

Python list:
[2, 4, 6, 8, 10]
Type: <class 'list'>

Converting a String Series

import pandas as pd
import numpy as np

animals = pd.Series(
np.array(['ant', 'bat', 'cat', 'dog']),
index=[100, 101, 102, 103]
)

print("Pandas Series:")
print(animals)

animal_list = animals.tolist()

print(f"\nPython list: {animal_list}")
print(f"Type: {type(animal_list)}")

Output:

Pandas Series:
100 ant
101 bat
102 cat
103 dog
dtype: object

Python list: ['ant', 'bat', 'cat', 'dog']
Type: <class 'list'>
note

When converting to a list, the index is discarded - only the values are included. If you need to preserve the index, convert both separately or use to_dict() instead.

Converting a Series Created from a Dictionary

import pandas as pd

marks = {'Maths': 100.0, 'Physics': 90.0, 'Chemistry': 85.0}

series = pd.Series(marks)

print("Pandas Series:")
print(series)

marks_list = series.tolist()

print(f"\nValues as list: {marks_list}")
print(f"Index as list: {series.index.tolist()}")

Output:

Pandas Series:
Maths 100.0
Physics 90.0
Chemistry 85.0
dtype: float64

Values as list: [100.0, 90.0, 85.0]
Index as list: ['Maths', 'Physics', 'Chemistry']

Converting a Slice of a Series

You can slice a Series first and then convert the subset to a list:

import pandas as pd

scores = pd.Series(
[100, 90, 80, 90, 85],
index=['Student1', 'Student2', 'Student3', 'Student4', 'Student5']
)

# Get first 3 students
top_three = scores[:3]

print("First 3 students:")
print(top_three)

print(f"\nAs list: {top_three.tolist()}")
print(f"Type: {type(top_three.tolist())}")

Output:

First 3 students:
Student1 100
Student2 90
Student3 80
dtype: int64

As list: [100, 90, 80]
Type: <class 'list'>

Alternative: Using list() Constructor

You can also use Python's built-in list() function to convert a Series:

import pandas as pd

series = pd.Series([10, 20, 30, 40])

# Method 1: tolist()
result1 = series.tolist()

# Method 2: list()
result2 = list(series)

print(f"tolist(): {result1}")
print(f"list(): {result2}")
print(f"Equal: {result1 == result2}")

Output:

tolist(): [10, 20, 30, 40]
list(): [10, 20, 30, 40]
Equal: True

Here is the corrected version of your section:


tolist() vs list() – Which to Use?

For a pandas Series, both usually produce the same result, and in most common cases there is no practical difference in element types.

import pandas as pd
import numpy as np

series = pd.Series([1, 2, 3], dtype=np.int64)

via_tolist = series.tolist()
via_list = list(series)

print(f"tolist() element type: {type(via_tolist[0])}")
print(f"list() element type: {type(via_list[0])}")

Output:

tolist() element type: <class 'int'>
list() element type: <class 'int'>

The difference appears with NumPy arrays, not typical pandas Series:

arr = np.array([1, 2, 3], dtype=np.int64)

type(arr.tolist()[0]) # int
type(list(arr)[0]) # numpy.int64

Here:

  • tolist() converts NumPy scalars to native Python types.
  • list() keeps NumPy scalar types.

For pandas Series:

  • Use tolist() when you want an explicit, clear conversion to a Python list (common in documentation and JSON serialization).
  • Use list() when you simply need iteration.

In most real-world pandas use cases, they behave the same.

Handling Missing Values (NaN)

When a Series contains NaN values, tolist() converts them to Python's float('nan') or None depending on the dtype:

import pandas as pd
import numpy as np

# Numeric Series with NaN
numeric = pd.Series([1.0, np.nan, 3.0, np.nan, 5.0])
print(f"Numeric with NaN: {numeric.tolist()}")

# String Series with None
strings = pd.Series(['apple', None, 'cherry'])
print(f"Strings with None: {strings.tolist()}")

Output:

Numeric with NaN: [1.0, nan, 3.0, nan, 5.0]
Strings with None: ['apple', None, 'cherry']

To replace NaN values before converting, use fillna():

import pandas as pd
import numpy as np

series = pd.Series([1.0, np.nan, 3.0, np.nan, 5.0])

# Replace NaN with 0 before converting
clean_list = series.fillna(0).tolist()
print(f"Cleaned list: {clean_list}")

Output:

Cleaned list: [1.0, 0.0, 3.0, 0.0, 5.0]

Converting DataFrame Columns to Lists

Since each DataFrame column is a Series, tolist() works on columns too:

import pandas as pd

df = pd.DataFrame({
'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [25, 30, 35],
'Score': [88.5, 92.3, 76.8]
})

names = df['Name'].tolist()
ages = df['Age'].tolist()

print(f"Names: {names}")
print(f"Ages: {ages}")

Output:

Names: ['Alice', 'Bob', 'Charlie']
Ages: [25, 30, 35]

Practical Example: Preparing Data for JSON

A common use case for tolist() is preparing pandas data for JSON serialization, since JSON doesn't support NumPy types:

import pandas as pd
import json

series = pd.Series([100, 200, 300], index=['a', 'b', 'c'])

# Convert to a JSON-compatible dictionary
data = {
'values': series.tolist(),
'labels': series.index.tolist()
}

json_string = json.dumps(data)
print(json_string)

Output:

{"values": [100, 200, 300], "labels": ["a", "b", "c"]}
JSON Serialization and tolist()

For a typical pandas Series with standard numeric dtypes, both list(series) and series.tolist() produce native Python types. So JSON serialization does not fail in this case.

import pandas as pd
import json

series = pd.Series([100, 200, 300])

# ✅ This works
json.dumps({'values': list(series)})

# ✅ This also works
json.dumps({'values': series.tolist()})

In pandas, iterating over a Series yields Python scalar values (int, float, etc.) for standard numeric dtypes. Therefore, both approaches are JSON serializable.

When Does JSON Serialization Fail? Serialization errors typically occur with NumPy arrays or NumPy scalar types:

import numpy as np
import json

arr = np.array([100, 200, 300], dtype=np.int64)

# ❌ Raises TypeError
json.dumps({'values': list(arr)})

Error:

TypeError: Object of type int64 is not JSON serializable

This happens because list(arr) contains numpy.int64 objects, which the standard json module cannot serialize.

Using:

json.dumps({'values': arr.tolist()})

works because tolist() converts NumPy scalars to native Python types.

Summary

MethodReturns Native Python Types*Preserves Index
series.tolist()✅ Yes❌ No
list(series)✅ Yes (for standard dtypes)❌ No
series.to_dict()✅ Yes✅ Yes (as dict keys)
series.values.tolist()✅ Yes❌ No

Conclusion

Converting a pandas Series to a Python list is simple and versatile:

  • Use series.tolist() for the cleanest conversion - it returns a standard Python list with native Python types, making it ideal for JSON serialization, API calls, and interoperability with non-pandas code.
  • Use list(series) when NumPy types are acceptable and you want a quick conversion.
  • Use series.index.tolist() when you also need the index values as a list.
  • Handle NaN values with fillna() before converting if your downstream code doesn't support missing values.

For most use cases, tolist() is the recommended and most reliable method.