Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to set a font and size to save information in pandas?

I need to save the extracted data in the same format, Arial font size 12.

Currently the code does not follow a pattern of font and size.

I tried using the utf-8 command and it didn’t work.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

df_conversas = pd.DataFrame({'Nomes': nomes_conversas})

df_conversas.to_excel('conversas.xlsx', encoding='utf-8', index=False)

>Solution :

You can use ExcelWriter with an engine :

df_conversas = pd.DataFrame({"Nomes": ["foo", "bar", "baz", "qux"]})

with pd.ExcelWriter("conversas.xlsx", engine="xlsxwriter") as writer:
    df_conversas.to_excel(writer, sheet_name="Sheet1", index=False)

    workbook = writer.book
    workbook.formats[0].set_font_name("Arial")
    workbook.formats[0].set_font_size(12)
    
    header_format = workbook.add_format(
        {"font_name": "Arial", "font_size": 12, "bold": True}
    )

    writer.sheets["Sheet1"].write(0, 0, "Nomes", header_format)

    #if you have more than a column, use this :
    #for idx, col in enumerate(df_conversas.columns):
    #    writer.sheets["Sheet1"].write(0, idx, col, header_format)

Output :

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading