Pandas Series

Pandas series is a One-dimensional ndarray with axis labels.The axis labels are collectively called index. It just a  column in an excel sheet.


pandas.Series([data, index, dtype, name, copy])

where :

  • data – python object
  • index – index (axis labels) of the Series
  • dtype – dtype object of the underlying data.
  • name – Return the name of the Series.
  • copy – Return a new object with updated flags

How to Create?

Creating a Python series from list object :

import pandas as pd
a = [11, 52,44,'hello']
data = pd.Series(a)

Using array() function :

import pandas as pd
import numpy as np
arr= np.array(['a','b','c','d','e'])
data= pd.Series(arr)

Using Key/Value(dict) Objects as Series:

The keys of the dictionary become the labels.

import pandas as pd

a = {"a": 1, "b": 2, "c": 3}

data = pd.Series(a)



The values are labeled with their index number and it can be used to access a specified value.

To create Labels use “index” argument.

import pandas as pd

a = [11, 57, 52,88]

data = pd.Series(a, index = ["a", "b", "c","d"])


How to Access Elements of Series?


To access the series element refers to the index number.The index must be an integer. In order to access multiple elements from a series, we use Slice operation.

import pandas as pd

data = ['a',2,'hello',4,5,'revin']

ser = pd.Series(data)


To access an element from series, we have to set values by index label.

import pandas as pd

data = ['a',2,'hello',4,5,'revin']

ser = pd.Series(data,index=[1,2,3,4,5,6])

Basic Selection of data

Viewing the top and bottom of the Series:


loc & iloc Method

The df.loc indexer selects data in a different way than just the indexing operator. It can select subsets of data.

The df.iloc indexer is very similar to df.loc but only uses integer locations to make its selections.


Leave a Reply

Your email address will not be published. Required fields are marked *