Find common values from a column of excel file using Python
In this tutorial, we are going to see how to find common values from a column of an excel file using Python. To do this we need to know about Pandas library. Pandas is an open-source library used for data science and data analytics.
First of all, we need to install the Pandas library:
! pip install pandas
Now let’s import the library to use its functions in code:
import pandas as pd
read_excel( ) function in pandas
Pandas library contains the read_excel( ) function which is used to read the excel file. You need to pass the file path as an argument to the function.
Note: The extension of the file must be (.xlsx)
Suppose you have an “IRIS” named excel file in your folder then you should write file path as:
data = pd.read_excel("F:\Aakanksha\Jupyter\IRIS.xlsx")
To get the overview of the excel file we can display a few rows from it.
There are two main functions available in pandas.
using head( ) function
The head() function returns the first 5 rows from the data file.
using tail( ) function
The tail() function returns the last 5 rows from the data file.
value_counts( ) function in pandas
To find the count of common values from a column of an excel file value_counts( ) function is used. It returns the common values along with their count in that particular column. (how much time it occurred in the column)
eg. The count of common values from the SPECIES column is: