Program to convert a given Series to an array

In this python pandas program, we will convert a given series to an array using NumPy and Pandas library.

Steps to solve the program
  1. Import pandas library as pd.
  2. Import NumPy library as np.
  3. Create a series using pd.Series().
  4. Now convert that series to an array using np.array(series_name.values.tolist())..
				
					import numpy as np
import pandas as pd
df1 = pd.Series([54,27.90,'sqa',33.33,'tools'])
print("Original Data Series:")
print(df1)
print("Series to an array")
result = np.array(df1.values.tolist())
print (result)
				
			

Output :

				
					Original Data Series:
0       54
1     27.9
2      sqa
3    33.33
4    tools
dtype: object
Series to an array
['54' '27.9' 'sqa' '33.33' 'tools']
				
			

change the data type of given a column or a Series

convert a series of lists into one series

Leave a Comment