pandas python re模块匹配不同的sheet_name

3
 

You can use pandas.ExcelFile to have a peek at the sheet names, then select the sheets to keep with any method (here your regex), finally load with pandas.read_excel:

import re

xl = pd.ExcelFile('filename.xlsx')

regex = re.compile('your_regex')

sheets = [n for n in xl.sheet_names if regex.match(n)]
# ['matching_sheet1', 'matching_sheet2']

dfs = pd.read_excel(xl, sheet_name=sheets)
#  {'matching_sheet1': DataFrame1,
#   'matching_sheet2': DataFrame2}



实例配置:


xl = pd.ExcelFile(raw_file)
 
regex = re.match('云数据库 RDS','云数据库 RDS MySQL')
 
sheets = [n for n in xl.sheet_names if n=="云数据库 RDS MySQL" or n=="云数据库 RDS"][0]
 
print(sheets)

  sheet_name 选择  云数据库 RDS MySQL或者 云数据库 RDS


posted @   Oops!#  阅读(29)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
历史上的今天:
2018-08-04 jenkins构建执行shell 所有命令出现command not found
2018-08-04 SSH限制ip登陆
点击右上角即可分享
微信分享提示