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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
2018-08-04 jenkins构建执行shell 所有命令出现command not found
2018-08-04 SSH限制ip登陆