Quick Discussion On Python Pandas

Introduction

 
Pandas is an opensource library built on top of Numpy. It allows for fast analysis, data cleansing, data preparation and has data visualization features. It can also work with data from a wide variety of sources.
 

How to install Pandas?

 
Go to your command line or terminal and use:
 
pip install pandas (if you have installed Python by directly going to here)
 
OR
 
conda install pandas (if you have Anaconda distribution of Python)
 
Either of the above should work. :)
 
Let’s start with the first data type while working with Pandas.
 

Series and how they interact with pandas

 
Series is very similar to a Numpy array (in fact it is built on top of the Numpy array object). What differentiates the NumPy array from a Series is that a Series can have axis labels, meaning it can be indexed by a label. It can hold any arbitrary Python object.
 
Let us import Pandas and explore the Series object.
 

Creating a Series

 
Python Pandas 
 
You can convert a list, Numpy array, or dictionary to a Series.
  • Using lists
Python Pandas 
 
It looks a lot like Numpy array except it has an index 0 1 2 and corresponding actual data.
 
Now, here we have Index that is labeled meaning we can call these data points using this labeled index. We can also directly use it like this:
 
Python Pandas
  • Using Numpy arrays.

    Python Pandas

  • Using Dictionary.

    Python Pandas
Note
A Pandas Series can hold a variety of object types. Such as,
 
Python Pandas 
 
Although we are not going to use it, a Panda Series is this flexible.
 

Grabbing data from Series

 
Here, we are creating two series and storing them. In order to grab data out of a series, we refer to the index such as,
 
Python Pandas 
 

Performing various operations on Series

 
We can also perform various with series such as addition,
 
Python Pandas 
 
Notice, what is happening, it's going to try to match up the operation based off the index. It has got matches for India and USA, so the operation has been performed here. But for other indices, there’s no match, so it has put a null(NaN object). Also, notice that the data type here is converted to float in order to retain all the information possible.
 
For division and multiplication see below,
 
Python Pandas 
 
Thanks for reading!
 
I hope you have enjoyed it throughout.
 
Note

There will be a continuation of this article. We will discuss Data Frame and how it works with Pandas. So keep reading!


Similar Articles