What does series mean in pandas?

PandasServer Side ProgrammingProgramming

The pandas Series is a one-Dimensional data structure, it is a similar kind of one-Dimensional ndarray, and is capable of holding homogeneous elements with any data type. It can store integers, strings, floating-point numbers, Python objects, etc.

Each value present in this pandas Series is represented with labels (indexes). By using these label names we can able to access any elements from the pandas Series.

The default index value of the pandas Series is from 0 to the length of the series minus 1, or we can manually set the labels.

Example

import pandas as pd
S1 = pd.Series([11,20,32,49,65])
print(S1)

Explanation

In this example, we can see a simple python pandas Series by using a list of integer values. initially, we have imported the python pandas package with the alias name pd. The pandas.Series() method is used to create a Series object.

Output

0   11
1   20
2   32
3   49
4   65
dtype: int64

In the above block, 0,1,2,3,4 are index values (labels), which are automatically created by the pandas Series function. And the numbers 11, 20, 32, 49, 65 are elements stored in the series object, here the data type of all the elements are int64.

Example

import pandas as pd
S = pd.Series({'a':'A','b':'B','c':'C'})
print(S)

Created another simple python pandas Series by using characters as elements and keys of the python dictionary are taken as the series index values automatically.

Output

a   A
b   B
c   C
dtype: object

The upper case letters and lower case letters are Series elements and label names respectively.

Pandas Series is an array-type object that will store 1-dimensional values with any data type. In the above two examples, we have seen the integer type and object type Series creation.

raja
Updated on 17-Nov-2021 07:12:58

Advertisements