Pandas Series.tolist() Function

Pandas Series.tolist() Function

  1. Syntax of pandas.Series.tolist():
  2. Example Codes: Series.tolist() Method to Convert a Series to List
  3. Example Codes: Series.tolist() Method to Convert a String Type Series to List

Python Pandas Series.tolist() function converts a series to list data type.

Syntax of pandas.Series.tolist():

Series.tolist()

Parameters

It has no parameters.

Return

It returns a list of the values of the series.

Example Codes: Series.tolist() Method to Convert a Series to List

import pandas as pd

series = pd.Series([ 1, 2, 3, 4, 5.5, 6.7])
print("The Original Series is: \n")
print(series)

series1 = series.tolist()
print("The List is: \n")
print(series1)

Output:

The Original Series is: 

0    1.0
1    2.0
2    3.0
3    4.0
4    5.5
5    6.7
dtype: float64
The List is: 

[1.0, 2.0, 3.0, 4.0, 5.5, 6.7]

The function has returned a list that contains the values of the series.

Example Codes: Series.tolist() Method to Convert a String Type Series to List

import pandas as pd

series = pd.Series([ 'Rose', 'Jasmine', 'Lili', 'Tulip', 'Hibiscus'])
print("The Original Series is: \n")
print(series)

series1 = series.tolist()
print("The List is: \n")
print(series1)

Output:

The Original Series is: 

0        Rose
1     Jasmine
2        Lili
3       Tulip
4    Hibiscus
dtype: object
The List is: 

['Rose', 'Jasmine', 'Lili', 'Tulip', 'Hibiscus']

The function has returned a list that contains string type values.

Related Article - Pandas Series

  • Pandas Series.head() Function
  • Pandas Series.to_frame() Function
  • Pandas Series Series.map() Function
  • Pandas Series Series.nunique() Function
  • Pandas Series Series.unique() Function