可以使用openpyxl库读取Excel文件,遍历每一列并判断是否存在连续两个数大于1100。如果存在则将该列的列号(即字母形式的列名)存储到一个列表中,最后返回该列表。

以下为示例代码:

import openpyxl

def check_excel(file_path):
    wb = openpyxl.load_workbook(file_path)
    ws = wb.active
    
    result = []
    
    for col in ws.iter_cols():
        col_num = col[0].column_letter
        prev_val = None
        
        for cell in col:
            if prev_val is not None and cell.value is not None:
                if prev_val > 1100 and cell.value > 1100:
                    result.append(col_num)
                    break
            prev_val = cell.value
        
    return result

使用示例:

file_path = 'example.xlsx'
cols = check_excel(file_path)
print(cols)

其中,file_path为Excel文件的路径,cols为返回的列号列表

使用python遍历excel中的每一列判断是否存在连续两个数大于1100并返回列数如果有多个列存在连续两个数大于1100则返回多个列数

原文地址: https://www.cveoy.top/t/topic/fTy0 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录