Ndarray in Pandas Series in Python by R4R Team

Series :
-series is one dimensional array defined in pandas library that can be used to store any data type.

Syntax-

pandas.Series(data,index)

Here data can be
1. scalar value like string,integer,float
2. python dictionary
3. Ndarray

-Here index part is optional, by default it is 0,1,2,3,4,......

Ndarray-

-Nested array or list

Example-

[[1,2],[3,4],[5,6]]

Ndarray with Series() :

program-

import pandas

#Ndarray
list=[[1,2,3],[4,5,6],[7,8,9]]

#with default index value
ans=pandas.Series(list)
print(ans)

#with alphabet index value
ans=pandas.Series(list,index=['a','b','c'])
print(ans)


output-

0[1, 2, 3]
1[4, 5, 6]
2[7, 8, 9]
dtype: object
a[1, 2, 3]
b[4, 5, 6]
c[7, 8, 9]
dtype: object

-In this program, we have a Ndarray like list=[[1,2,3],[4,5,6],[7,8,9]], then we pass in Series() function then it will shown the above output.




Leave a Comment: