VOOZH about

URL: https://www.geeksforgeeks.org/python/python-pandas-series-tolist/

⇱ Pandas Series.tolist() - Python - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Pandas Series.tolist() - Python

Last Updated : 18 Mar, 2025

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.


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.


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.


Output
[1.0, 2.0, nan, 4.0]

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

Comment