python导入特定的sheet页,行,列数据

示例中的excel数据有多个sheet多行多列数据,现在想读取特定sheet页,特定的行列数据

查询指定sheet页内容

import  pandas as pd

df = pd.read_excel(r'C:\Users\12133\Desktop\test.xlsx') 
#不加参数默认为第一个sheet页内容

print(df.head())

 

import  pandas as pd

df = pd.read_excel(r'C:\Users\12133\Desktop\test.xlsx',sheet_name=[0,1,'测试sheet3'])
#sheet_name()   第一页数据 
#sheet_name = 1   第二个sheet页数据
#sheet_name = "用户借书记录"   指定名称的sheet页数据
#sheet_name = [0,1,"用户借书记录"]  取第1页,第2页和指定名称的sheet页数据

print(df)

 查询指定行列内容

import  pandas as pd

def print_excel():
    # Use a breakpoint in the code line below to debug your script.
    pd.set_option('display.unicode.east_asian_width',True)
    df1 = pd.read_excel(r'C:\Users\12133\Desktop\test.xlsx',sheet_name = ['用户购买记录'],nrows=1,usecols=[0,2])
    #nrows:导入前多少行
    #usecols[0,2]:导入指定的第1行和第3行数据
    #usecols['用户名','支付金额(元)']:导入指定的名称行的数据
    print(df1)  #head():默认输出前5条

# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    print_excel()

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值