zoukankan      html  css  js  c++  java
  • python 读取不同的列,判断然后将结果写入excel

    # -*- coding:utf-8 -*-

    #将excel中数据转换成列表,然后对比,然后对比结果放到excel中
    import xlrd
    from xlutils import copy
    excel_path = 'D:/abnormal.xls' # 文件路径
    rbook = xlrd.open_workbook(excel_path)
    w_sheet = rbook.sheet_by_name(u'sheet1')
    rowNum = w_sheet.nrows

    cols_data=w_sheet.col(1, start_rowx=1, end_rowx=None) #第2列所有数据
    list_110 = []
    for a_row in cols_data:
    # 遍历每一行的单元格
    list_110.append(a_row.value)
    print('xxxxx:',list_110)


    cols_data_new=w_sheet.col(2, start_rowx=1, end_rowx=None) #第3列所有数据
    list_110_new = []
    for a_row in cols_data_new:
    # 遍历每一行的单元格
    list_110_new.append(a_row.value)
    print('xxxxx:',list_110_new)


    wbook = copy.copy(rbook)    #在已经存在的excel中写入数据
    w_sheet1 = wbook.get_sheet(0)
    w_sheet1.write(0, 3, '结果')
    i=0
    for i in range(rowNum):
    if (list_110[i]!='')&(list_110_new[i]!=''):
    if float(list_110[i])>=float(list_110_new[i]):
    w_sheet1.write(i+1, 3, 'Pass')
    else:
    w_sheet1.write(i+1, 3, 'Fail')
    else:
    w_sheet1.write(i+1, 3, 'N/A')

    wbook.save(excel_path)

  • 相关阅读:
    TCP/IP
    logging模块
    HttpClient当HTTP连接的时候出现大量CLOSE_WAIT连接(转)
    三 os模块
    一 time与datetime模块
    (转)HTTPS到底是个啥玩意儿?
    Python
    Codeforces Round #374 (Div. 2)
    Codeforces Round #373 (Div. 2)
    bzoj3527: [Zjoi2014]力
  • 原文地址:https://www.cnblogs.com/xiaochengzi2018/p/15525937.html
Copyright © 2011-2022 走看看