gpt4 book ai didi

python - 重温问题 "How to read specific sheets from My XLS file in Python"

转载 作者:行者123 更新时间:2023-12-04 21:27:17 25 4
gpt4 key购买 nike

我遇到了与以下讨论相同的问题:
How to read specific sheets from My XLS file in Python
我在我的代码中使用了该讨论中提到的方法

import numpy as np
import os
import pandas as pd


folder = r'C:\Users\Denny\Desktop\Work\no_solution'
files = os.listdir(folder)
dfs = {}
for file in files:
if file.endswith('.xlsx'):
dfs[file[:-5]] = pd.read_excel(os.path.join(folder,file), sheet_name='Z=143', header = None, skiprows=[0], usecols = "B:M")
这里我有两张纸,第一张叫做“sheet”,另一张叫做“Z=143”。所以在代码中,我添加了 sheet_name='Z=143' .
enter image description here
但是,它显示以下错误
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\Denny\\Desktop\\Work\\no_solution\\~$T2405.6Mhz.xlsx'
我试图把“Z=143”放在不同的位置;但是,它失败了。
我该如何克服这个问题?提前致谢!

最佳答案

问题在于您的循环 if陈述

for file in files:
if file.endswith('.xlsx') and not file.startswith('~'):
dfs[file[:-5]] = pd.read_excel(os.path.join(folder,file), sheet_name='Z=143', header = None, skiprows=[0], usecols = "B:M")
我添加的条件确保您不会读取 excel 为打开文件创建的临时文件

关于python - 重温问题 "How to read specific sheets from My XLS file in Python",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69061672/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com