Saturday, September 21, 2024
Google search engine
HomeLanguagesHow to import excel file and find a specific column using Pandas?

How to import excel file and find a specific column using Pandas?

In this article, we will learn how to import an excel file into a data frame and find the specific column. Let’s suppose our excel file looks like this.

Sample_data.xlsx

Excel sheet Link: https://drive.google.com/file/d/1x-S0z-gTo–H8byN12_MWLawlCXfMZkm/view?usp=sharing

Approach :

  • Import Pandas program
  • Create a DataFrame
  • Store Excel data into DataFrame
  • Check the specific column and display with head() function

Below is the implementation.

Step 1: Import excel file.

Python3




# importing module
import pandas as pd
  
  
# creating dataframe
# importing excel file
df = pd.read_excel('Sample_data.xlsx')  
df.head()


Output :

Step 2: Check the specific column and display topmost 5 value with the head()

Python3




df[df["Country"] == 'Canada'].head()


Output :

Another column with the same methods.

Python3




df[df["Year"] == 2013].head()


Output :

Another column with the same methods.

Python3




df[df["Segment"]=='Government'].head()


Output :

RELATED ARTICLES

Most Popular

Recent Comments