Introduction to Pandas DataFrames Analyzing

In This Article, You Will Learn About Python Pandas DataFrame Analyze

Python Pandas Read – Before moving ahead, let’s know about Pandas CSV & JSON

Viewing the Data

Using head() method allows us to get the quick view of DataFrame.

It returns headers and rows by specifying the number of rows, starting from top or first row.

Table of Contents

Example – Returning a quick view of first 8 rows of the DataFrame.

				
					import pandas as pd

info = pd.read_csv('data.csv')

print(info.head(8))

				
			

As shown above, it returned top-first 8 rows of data. 

Note: Index number in Python starts from zero. 

Note: if the number of rows is not specified, the head() method will return the top 5 rows.

				
					import pandas as pd

info = pd.read_csv('data.csv')

print(info.head())

				
			

Click to Download File

As a result above, it returned top-first 5 rows of data by default. 

There is one more method of DataFrame i.e., tail() method that returns headers and rows by specifying number of rows; starting from bottom.

Example – Returning by default first 5 rows of the DataFrame.

				
					import pandas as pd

info = pd.read_csv('data.csv')

print(info.tail())

				
			

As shown above, it returned bottom-first 5 rows of data. 

info in DataFrame

The DataFrame has a method called info() that returns an additional information of data-set such as number of rows  & columns, and class-type etc.

Example – Returning huge amount of data of DataFrame.

				
					import pandas as pd

df = pd.read_csv('data.csv')

print(df.info())

				
			

As shown above, it returned additional information of data such as total number of rows & columns. Class type and memory usage etc.

Result Explained

The result tells there are 20 rows and 5 columns:

RangeIndex: 20 rows, 0 to 20.

Data columns : total 5 columns.

Null Values

The info() method also tells us how many Non-Null values there are present in each column.

Values that are empty, or null values, could be harmful when it comes to analyzing data. It must consider eliminating rows with columns that have empty values.

If you find anything incorrect in the above-discussed topic and have any further questions, please comment below.

1 thought on “Introduction to Pandas DataFrames Analyzing”

Leave a Comment

Stay in the loop

codingstreets