如何使用Pandas导入excel文件并找到特定的列

如何使用Pandas导入excel文件并找到特定的列

在这篇文章中,我们将学习如何将一个excel文件导入到一个数据框架中并找到特定的列。我们假设我们的excel文件是这样的。

如何使用Pandas导入excel文件并找到特定的列?

Excel表链接:https://drive.google.com/file/d/1x-S0z-gTo-H8byN12_MWLawlCXfMZkm/view?usp=sharing

步骤 :

  • 导入Pandas程序
  • 创建一个数据框架
  • 将Excel数据存储到DataFrame中
  • 用head()函数检查特定列并显示

以下是实现情况。

第1步:导入excel文件。

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

输出 :

如何使用Pandas导入excel文件并找到特定的列?

第2步:检查特定的列,用head()显示最上面的5个值。

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

输出 :

如何使用Pandas导入excel文件并找到特定的列?

另一个专栏也有同样的方法。

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

输出 :

如何使用Pandas导入excel文件并找到特定的列?

另一个专栏也有同样的方法。

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

输出 :

如何使用Pandas导入excel文件并找到特定的列?

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

登录

注册