Thursday, October 22, 2020

How to format the XL file with headers formatted

from openpyxl.utils.dataframe import dataframe_to_rows

wb = Workbook()

ws = wb.active


for r in dataframe_to_rows(df, index=True, header=True):

    ws.append(r)

wb = Workbook()

ws = wb.active


for r in dataframe_to_rows(df, index=True, header=True):

    ws.append(r)


for cell in ws['A'] + ws[1]:

    cell.style = 'Pandas'


wb.save("pandas_openpyxl.xlsx")


References:

https://stackoverflow.com/questions/55041209/openpyxl-mark-row-as-heading




Dataframe how to change col Order 


column_names = ["C", "A", "B"]

df = df.reindex(columns=column_names)



References:

https://www.kite.com/python/answers/how-to-reorder-columns-in-a-pandas-dataframe-in-python


No comments:

Post a Comment