Import Pandas as pd
Tags: Coronavirus, Covid 19, Data Science, Data Analysis, Pandas

Here, I give you a high-level explanation of pandas for absolute beginners. Before start learning pandas, it is better to have the knowledge of basic python programming language. Get ready for the quick overview.

Pandas is just a library of python used for data manipulation and analysis.

Manipulation: Manipulation is the word used to describe skillful handling, controlling, or using something. Analysis: Analysis is breaking down something into pieces to learn.

We do manipulation and analysis of data using pandas. So, after importing the data, you can play with the data as you want with pandas. Pandas will work for your command like a servant. You just need to know how to command your servant. That means you should command in the language that your servant could understand. Now I hope you got a clear idea of how pandas work.

Import Pandas

If you want to use the Pandas module in your working path. Just import it with the following command. It is like calling your servant to work for you.

import pandas as pd

Wait, before that ensure if you have downloaded the pandas in your machine. If not, download the package using the following code(in terminal). Before calling your servant to do your work, appointing someone in that position is important, right?

pip install pandas

Okay, lets come to the game again. why we are importing pandas as pd here? I explain, how do we call if someone has a lengthy name? Just with a short name, right? That’s how it works. Cool! (You can use any name as you want)

import pandas as servant

This also will work, go…

What is Dataframe?

Dataframe is the two-dimensional data structure (a combination of rows and columns). Take a look below.

Dataframe

Here is nothing to mix up. Think of an excel spreadsheet. That’s what the dataframe is.

Components of Dataframe

Series: Each column in a dataframe is series. Series is a one-dimensional structure. A combination of two interrelated series is a dataframe.

Example: Arrays.

Label: Each column heading is the label. It is also called a variable. Name, Age, and Gender are the labels of the respective column in the above dataframe.

Now let’s know how to construct a Dataframe in pandas. Now here you are going to command your servant to construct a dataframe for you. As I already said, to do this, you should tell him in the language which he could understand. Your servant doesn’t know the English language, but he knows the syntactical language. Let’s learn his syntactical language. Come on…

Pd.DataFrame()

Whenever you order something to do, say with an open and close bracket. I here explain in a comprehensible way that how it actually works. If you do like that, So he can understand that he has to do a favor. He has some inbuilt function in his brain. If you mention your work with those brackets, he will search in his brain whether the function(the work you assigned to do) is inbuilt in his brain or not. If it is inbuilt, he knows how to do and he will do it for you. If not, he throws an error. Now pd(servant) will search in his brain for the function Dataframe() in his brain. Yes, it is inbuilt. So now he will do that work with your given data and present in a way as you expected.

So whenever you see function, visualize how I explained above.

Let’s see how it works,

Empty DataFrame

I didn’t give any data in it, so it just created an empty dataframe. Now let’s try with passing some data in it.

Dataframe

Now it created a perfect dataframe. It automatically created an index for our dataframe as 0,1,2… There are a lot of constructors(options) we can use inside the dataframe function. Functions are the work we are assigning to pandas and constructors are like we are defining how to do that work. Cool, right?

If we want to see the data type of the dataframe we created, just execute this code.

type(df)

Datatype of Dataframe

Now let’s try passing the list in the dataframe.

We all know that list is a one-dimensional thing, right?

Then how we can pass this in a two-dimensional dataframe?

How the dataframe will be if we create a dataframe out of a list?

Dataframe created using the list

Here you go, it created a single column for us with the default index. Pandas dataframe can be created using various inputs like List, Dictionary, Series, Numpy ndarrays, and another Dataframe.

Keep practicing alongside. Happy Learning!