сравнить два столбца и цвет больше в Excel с помощью Python? - PullRequest
0 голосов
/ 27 ноября 2018

Я сталкивался с условным форматированием https://xlsxwriter.readthedocs.io/working_with_conditional_formats.html Но не уверен, как это реализовать.Я сохранил свой результат в dataframe, я пытаюсь сделать это форматирование цвета на основе, если column2> column1: color column2 else: ничего не делать и сохранить файл Excel.любые предложения.

1 Ответ

0 голосов
/ 30 ноября 2018
for row in table:
    ws.write_row(i, 0, row)

    i += 1
    print("for i:", i)
    cell_pointer1 = "C${}".format(i) 
    cell_pointer2 = "D${}".format(i) 
    cell_pointer3 = "E${}".format(i) 
    print("cell pointer2:", format(cell_pointer2))

    ws.conditional_format(format(cell_pointer2) ,
        {'type':     'cell',
         'criteria': '>=',
         'value' : format(cell_pointer1),
         'format':   format2,
        })


    ws.conditional_format(format(cell_pointer2) ,
        {'type':     'cell',
         'criteria': '<',
         'value' : format(cell_pointer1),
         'format':   format1
        })

    ws.conditional_format(format(cell_pointer3) ,
       {'type':     'cell',
        'criteria': '>=',
        'value' : format(cell_pointer1),
        'format':   format2,
       })


    ws.conditional_format(format(cell_pointer3) ,
       {'type':     'cell',
        'criteria': '<',
        'value' : format(cell_pointer1),
        'format':   format1
       })

ws.set_column (0, 0, 25)

wb.close ()

...