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.

Contribute
DelftStack is a collective effort contributed by software geeks like you. If you like the article and would like to contribute to DelftStack by writing paid articles, you can check the write for us page.

Related Article - Pandas Series

  • Pandas Series Series.value_counts() Function
  • Pandas Series.to_frame() Function