Introduction To Pandas

Pandas

Pandas is a fast, powerful, flexible, and easy to use open-source data analysis and manipulation tool,
built on top of the Python programming language.

In this blog, I will give you an idea of how pandas work and how you can analyze and process the data with the help of pandas. We will go through some scripts and will explain everything.

So open your colab Notebook and have fun.

Importing Libraries :

We will import the two most important libraries responsible for processing and analyzing the data, You must have guessed by now. They are NumPy and pandas.

import numpy as np
import pandas as pd

Converting a Dictionary into a DataFrame :

What is a DataFrame ?

A Pandas DataFrame is a 2-dimensional data structure, like a 2-dimensional array, or a table with rows and columns.

emp_details = {
    'name':['Bill','Mark','Elon','Jack'],
    'Company':['Microsoft','Facebook','Tesla','Alibaba'],
    'age':[65,44,45,50]
}

Now, this is a dictionary, to convert this data in a DataFrame, all you need to do is to use a DataFrame method.

df = pd.DataFrame(emp_details)
df

Output :

Converting DataFrame to CSV File :

To Convert DataFrame into a CSV File, All you need to do is :

df.to_csv('Entrepreneurs.csv')

Output :

It will create a CSV file to your default path location, in your project. You can go and look for it.

To get First or Last Few rows :

Data can be huge, and if you only want to work on a few top or bottom rows to see the trend. All you need to do is :

df.head(2)

Output:

df.tail(1)

Output :

To calculate some statistical data like percentile, mean and standard deviation of the numerical values:

The describe() method is used for calculating some statistical data like percentile, mean, and std of the numerical values of the Series or DataFrame.

df.describe()

Output :

To Read CSV File :

We will use a method to read any file such as :

mydata = pd.read_csv('Entreprenurs.csv')
mydata

Output :

pandas

Indexing :

mydata['name']

Output :

Want to Change Indexes ?

mydata.index = [1,2,3,4]
mydata 

Output :

So you must have realized it is really easy to work on pandas if you know the methods. I will cover how to implement this knowledge on datasets and analyze it in some other blog. GoodDay.

pandas

One thought on “Introduction To Pandas

Leave a Reply

Your email address will not be published.

Back To Top