小编MPJ*_*567的帖子

计数字符串参数

是否有内置函数或计数字符串中参数数量的好方法。例如:

"Here is my {}, and it has a {}"
Run Code Online (Sandbox Code Playgroud)

我希望能够确定该字符串中的参数数量为2,因此我可以将此值用于循环以从用户那里获取输入。

python python-3.x

0
推荐指数
1
解决办法
53
查看次数

如何返回到for循环中的特定点?

我有一系列嵌套循环,循环遍历多个 excel 文件,并根据对内容的检查,将内容添加到数据框列表中。

在某种情况下,我需要跳出当前循环,而不是添加到数据框列表中,并继续解析下一个 excel。不幸的是,我无法弄清楚如何设置循环以完成我想要的行为。

目前代码如下。我添加了解释我正在寻找什么行为的评论。

for name in folder_names:
path = rf'I:\PATH\{name}'
file_list = [f for f in glob.glob(path+"/*.xlsx")]
df_list = []
for f in file_list: #if a break event is triggered, I need to return here.
    xl = pd.ExcelFile(f)
    if len(xl.sheet_names) == 1:
        wb = load_workbook(f, data_only = True)
        sh = wb.worksheets[0]
        ColNames = {}
        Current  = 0
        for COL in sh.iter_cols(1, sh.max_column):
            ColNames[COL[0].value] = Current
            Current += 1
        for row_cells in sh.iter_rows(min_row=2, max_row=len(sh['D'])):
            if row_cells[ColNames['XXXX ID']].fill.start_color.index != …
Run Code Online (Sandbox Code Playgroud)

python python-3.x

0
推荐指数
1
解决办法
53
查看次数

标签 统计

python ×2

python-3.x ×2