Creation of Pandas Series:

Pandas series is one dimensional labeled array which is capable of holding data of any type (string, integer, float, etc.). Collectively in data science, the axis labels are known as index in python. Pandas series is a column in excel sheet. Labels do not need to be unique, but it must be of hashable type. The object will support both integer and label based indexing and will provide the host with a method for performing operations involving the index.

Creation of empty series:

Creation of Pandas Series in Python for Data Science - PST Analytics

Creation of series from array:

For the creation of a  series from array we need to import numpy module and use array() function.

Creation of Pandas Series in Python for Data Science - PST Analytics

OUTPUT:

Creation of Pandas Series in Python for Data Science - PST Analytics

Creation of series from array with index:

For the creation of series from array with index we need to provide index with the same number of elements as is present in the array.

OUTPUT:

Creation of series from lists:

For the creation of series from lists, first of all we need to create a list and then as series from the list.

OUTPUT:

Creation of series from dictionary:

For the creation of a series from a dictionary, we need to create a dictionary first, and then make a series using that dictionary. The dictionary keys are there for constructing an index.

OUTPUT:

Creation of Pandas Series in Python for Data Science - PST Analytics

Creation of series from scalar values:

We need to provide an index for the creation of a series from scalar values. The scalar value is repeated for matching the length of the index.

OUTPUT:

Creation of a series using NumPy functions:

Different functions of numy such as numpy.linespace(), numpy.random.radn(), etc. are there for the creation of series from NumPy functions.

OUTPUT:

So, to learn more about pandas in python for data science, you can check this and this as well.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.