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

2 COMMENTS

Most Popular

Dominic
32745 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7131 POSTS0 COMMENTS
Nicole Veronica
12258 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12345 POSTS0 COMMENTS
Shaida Kate Naidoo
7240 POSTS0 COMMENTS
Ted Musemwa
7504 POSTS0 COMMENTS
Thapelo Manthata
7224 POSTS0 COMMENTS
Umr Jansen
7190 POSTS0 COMMENTS