Pandas series- Attributes and Methods

Pandas series is another type of python object which is having separate set of attributes and methods to work upon. It is a single dimensional array and we have to maintain the consistency over the series, pandas series will accept any type of data but it is a good practice to maintain the data type consistency over the series.


Attributes- Will provide additional information about the underlying object but won't perform any manipulation on series values to provide the final result.

Methods- Will operate on underlying object and takes the series values, performs some computation/manipulation to provide us the final result.


1.Creating a series using python list

To create a python list, we can make use of the Series() method from pandas package.

import pandas as pd

animal=["four legs","rude","birds","lion"]

series=pd.Series(animal)

I have given the code snippet to implement the same


2.Example of attribute

In order to get an idea about attributes we are going to call an attribute called 'values' on the series.


We can see that values attribute just give us the values present in the series but note that it is returning in an array which will be very useful when we are implementing machine learning algorithms and no manipulation has been performed to the underlying series object.


3.Example of Methods


In this case, new series called 'numbers' has been created and the method sum() has been called upon the object, sum() takes all the values in the 'numbers' series and performs the addition to return the final value.


Jupyter notebook for this post is available here Github








0 views

©2019 by MLMaestro.com