[Python] Pandas to Excel - make part of the text bold

Discussão em 'Python' iniciado por Stack, Janeiro 30, 2025.

  1. Stack

    Stack Membro Participativo

    Is there a way to make part of the string/cell bold in Pandas? I'm working with plenty of textual data, exporting to Excel and then using it in Word as linked content, so I can't format it after it gets exported since the data changes pretty often.

    Simplified example:

    import pandas as pd

    df = pd.DataFrame([["Hello world."], ["Hello bold world."]], columns = ["example"])

    writer = pd.ExcelWriter('sample.xlsx', engine='xlsxwriter')
    df.to_excel(writer, sheet_name='Sample', index=False)
    writer.save()


    I want to make "bold" in bold. Is there a way or another way how to highlight just part of the string?

    I've tested using **bold**, <b>bold</b>, '\033[1mbold\033[0m' but no success at all.

    Continue reading...

Compartilhe esta Página