[Python] Pasting pandas dataframe output to Outlook gives wrong alignment due to tabs/spaces

Discussão em 'Python' iniciado por Stack, Julho 24, 2025.

  1. Stack

    Stack Membro Participativo

    My goal is sending nicely formatted output of a pandas dataframe via text e-mail in Outlook 365, Windows 11, desktop client. The problem is, that when copying and pasting the output into Outlook, tabs and spaces are being messed up.

    import pandas as pd

    df = pd.DataFrame({'foo': ['bar', 'Barbaras Rhabarberbar'],
    'Krabbenbazar': ['Rhabarberbarbar', 'foo']})
    print(df)


    Gives a nicely formatted output:

    foo Krabbenbazar
    0 bar Rhabarberbarbar
    1 Barbaras Rhabarberbar foo


    I'm left-aligning this using the tabulate package:

    from tabulate import tabulate
    print(tabulate(df, showindex=False, headers=df.columns))


    which gives

    foo Krabbenbazar
    --------------------- ---------------
    bar Rhabarberbarbar
    Barbaras Rhabarberbar foo


    I can copy and paste this easily into most text-processors or text-fields, preserving the formatting. However, when I copy and paste to Outlook, the alignment is messed up:

    [​IMG]

    Why is this happening and how can I keep the alignment?

    Continue reading...

Compartilhe esta Página