Untitled
unknown
plain_text
a year ago
1.3 kB
6
Indexable
Never
from time import perf_counter import pandas as pd from openpyxl.styles import PatternFill, Font def get_data_frame(): d = {'col1': [i for i in range(1, 100000)], 'col2': [i for i in range(1, 100000)]} return pd.DataFrame(data=d) fill = PatternFill(start_color="FFC7CE", end_color="FFC7CE", fill_type="solid") ft = Font(color="FF0000") def v1(): writer = pd.ExcelWriter("v1.xlsx", engine="openpyxl") df = get_data_frame() df.to_excel( writer, startrow=0, startcol=0, index=False, ) for column in writer.book.worksheets[0].iter_cols(min_row=0, min_col=0): for cell in column: cell.fill = fill writer.close() def styler(row): return pd.Series(["background-color : red;" for _ in row]) def v2(): writer = pd.ExcelWriter("v2.xlsx", engine="openpyxl") df = get_data_frame() styled = df.style.apply(styler) styled.to_excel(excel_writer=writer, index=False) if __name__ == "__main__": t1_start = perf_counter() v1() t1_stop = perf_counter() print("V1 Elapsed time during the whole program in seconds:", t1_stop - t1_start) t2_start = perf_counter() v2() t2_stop = perf_counter() print("V2 Elapsed time during the whole program in seconds:", t2_stop - t2_start)