Tags do not have to be unique, but must be hashable. The object supports both integer and label-based indexing and provides many methods for performing index operations.
Create empty series:
Basic series, which you can create, — this is an Empty Series.
|
Exit:
Series ([], dtype: float64)
Creating a series from an array:
To create a series from an array, we should import the numpy module and use the array () function.
|
Output:
Creating a series from an array with an index:
To create a series from an array with an index, we must provide an index with the same element number as in the array.
|
Output:
Output: Output: Creating a series using numpy functions : import
pandas as pd
# simple list
list
=
[
’g’
,
’ e’
,
’e’
,
’ k’
,
’s’
]
# create series from the list
ser
=
pd.Series (
list
)
print
(ser)
import
pandas as pd
import
numpy as np
# giving a scalar value with an index
ser
=
pd.Series (
10
, index
=
[
0
,
1
,
2
,
3
,
4
,
5
])
print
(ser)
To create a series using numpy function, we can use various numpy functions such as numpy.linspace () , randn-python/ target=_blank> numpy.random.radn ( ) .
|
Output: