w3resource

Pandas: Convert a Panda module Series to Python list and it’s type

Pandas: Data Series Exercise-2 with Solution

Write a Pandas program to convert a Panda module Series to Python list and it’s type.

Sample Solution :

Python Code :

import pandas as pd
ds = pd.Series([2, 4, 6, 8, 10])
print("Pandas Series and type")
print(ds)
print(type(ds))
print("Convert Pandas Series to Python list")
print(ds.tolist())
print(type(ds.tolist()))

Sample Output:

Pandas Series and type                                                 
0     2                                                                
1     4                                                                
2     6                                                                
3     8                                                                
4    10                                                                
dtype: int64                                                           
<class 'pandas.core.series.Series'>                                    
Convert Pandas Series to Python list                                   
[2, 4, 6, 8, 10]                                                       
<class 'list'>                                                      

Python Code Editor:


Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Pandas program to create and display a one-dimensional array-like object containing an array of data using Pandas module.
Next: Write a Pandas program to add, subtract, multiple and divide two Pandas Series.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz



Python: Tips of the Day

Python: Membership Testing in a Collection

>>> a = ('one', 'two', 'three', 'four', 'five')
>>> if 'one' in a:
...     print('The tuple contains one.')
... 
The tuple contains one.
>>> b = {0: 'zero', 1: 'one', 2: 'two', 3: 'three'}
>>> if 2 in b.keys():
...     print('The dict has the key of 2.')
... 
The dict has the key of 2.