In this python pandas program, we will convert a given series to an array using NumPy and Pandas library.
Steps to solve the program
- Import pandas library as pd.
- Import NumPy library as np.
- Create a series using pd.Series().
- 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']