What is Series in Pandas? Data Science full course in Hindi for free | Free course Data Science

Series is one-dimensional labeled array in Python Pandas which is capable of holding data of any type i.e. integer, float, characters, etc. The axis labels are collectively called index.



How Series can be Created?

It can be created using list, numpy arrays, from dictionaries, from scaler objects, etc. Let us explore it one by one.

Syntax:-

Import pandas as pd

Pd.Series(data, index, dtype)

Where pd is pandas alias, Series is Function through which we create it Series, data is the data we are creating, index is index of data and dtype is type of the data.

 

    1. Create Series from Python List:-

Pandas Series can be created by Python List. We can create python list and there after call Python’s Pandas Series function to convert List into Series.

Let us understand it by Code:-

Create series for list


 Explanation:-

First we imported modules and created a Python's list (list1). After that we called Pandas Series Function to convert Python List into Series.

Here we have not passed any index, It will take an index as numeric numbers starting range from 0 to n.

We will discuss about index in next Example.


2. Create Pandas Series by passing values:-

Yes, you heared it right. We can create Pandas' Series by just passing values and index(optional). 

Syntax:-

pd.Series(data, index=index)

Let us Create Python Pandas' Series:-

create Series in Pandas

Here index is the a,b,c,d because we explicitly declare index as a,b,c,d.


3. Create an Empty Series:-

We can also create an Empty Series. All we have to do is just pass the empty data in Series.

Let us understand:-

create empty series


4. Create Series from Numpy Arrays:-

Yes, we can also create Series from Numpy nd-arrays. All we need to import Pandas and NumPy array as well. Create Array using Numpy and Pass the variable into Series function. Done, your series created.

Let us understand it by code:-

Array form numpy array

OutPut:-


We can also pass index to provide indexing to our data.


Note:-

We can not create 2-D array in Series else it will throw error

Code:-

2d array in series

Output:- 

It will throw the following Error - Data must be 1- Dimensional


Conclusion:-

We can not pass 2-D array in Series otherwise we will get error like this. Let us jump to next method.


5. Create a Series by Python Dictionary

We can also create Series by dictionaries. When we talk about Dictionaries it contains key-value pair but in Series, we only have 1-D arrays. So that's why Dictionaries Key becomes index and values remains the data of the Series

Let us understand it by Code:- 

Create Series by Dictionaries

As shown in the picture, key becomes indexes and value becomes Data.

In the next Post we will discuss about how to access data from series?


I hope you loved this post. Kindly Subscribe to our Youtube channel - Codin India
where we will learn Data Science with Python in Hindi and many more.


If you want to learn Data Science in Hindi - Data Science Full Course in Hindi

If you want to learn Numpy in Hindi - NumPy Tutorial

If you want to learn Full Stack web development in Hindi - Full Stack Web Development in Hindi

If you want to learn Python Programming - Python Programming in Hindi

Comments