Skip to content
Related Articles

Related Articles

How to import excel file and find a specific column using Pandas?
  • Last Updated : 05 Sep, 2020

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 :

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :