Open In App

Pandas Series.tolist() - Python

Last Updated : 18 Mar, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The tolist() method in Pandas is used to convert a Pandas Series into a Python list. This method returns a new list containing all the elements of the Series in order. Let’s look at an example to understand its usage.

Python
import pandas as pd

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

# Convert Series to a list
a = s.tolist()
print(a)
print(type(a)) # Check the type of the output

Output
[10, 20, 30, 40]
<class 'list'>

Examples of tolist() Method

1. Converting a Series with Mixed Data Types

This example highlights how tolist() converts a Pandas Series with different data types, including integers, strings, floating-point numbers, and booleans, into a Python list while preserving their types.

Python
import pandas as pd

s = pd.Series([1, "hello", 3.14, True])

a = s.tolist()
print(a)

Output
[1, 'hello', 3.14, True]

Explanation: The Series contains elements of different data types (integer, string, float, boolean), and tolist() converts them into a list while maintaining their types.

2. Converting a Series with NaN Values

When a Pandas Series contains missing values (NaN), the tolist() method converts them to numpy.nan in the resulting list, ensuring consistency with NumPy's handling of missing data.

Python
import pandas as pd
import numpy as np

s = pd.Series([1, 2, np.nan, 4])

lst = s.tolist()
print(lst)

Output
[1.0, 2.0, nan, 4.0]

Explanation: The NaN value in the Series is represented as nan in the list output.


Next Article

Similar Reads