Pandas:显示整行而不截断

Pandas: Show entire rows without truncation

我有一个 python 脚本,可以在使用 AWS SNS 失败时发送电子邮件。我遇到了数据框被截断的问题,我不确定如何显示整个线程。我试过使用 pandas set_option 但这似乎没有任何效果。

有没有办法打印出整个数据框并显示整行?

这是一小段代码:

import pandas as pd
import boto3
pd.set_option('display.max_columns', None)
pd.set_option('display.max_rows', None)

session = boto3.Session()
sns = session.client('sns', region_name='us-east-1')

d = {'failed_runs':['296e62fb-1bc2-4e27-8d69-4a2267237698 - FAILED-GSN-INTO', '92b15078-1fcc-41f0-bc20-d933becf23bf - FAILED-ESP2-INTO', 'b04460ef-32a7-403a-8fbe-468effed7f2b - FAILED-HLN-INTO']}

df = pd.DataFrame(d)

response = sns.publish(TopicArn="arn:aws:sns:xxxxxxxxx",
                       Message="""
        Daily Digest for Failed Runs
        ------------------------------------------------------------------------------------

        {}

        ------------------------------------------------------------------------------------


        """.format(df))

这给我一封电子邮件,例如:

       Daily Digest for Failed Runs
       ------------------------------------------------------------------------------------

                                                  failed_runs
0   296e62fb-1bc2-4e27-8d69-4a2267237698 - FAILED-...
1   92b15078-1fcc-41f0-bc20-d933becf23bf - FAILED-...
2   b04460ef-32a7-403a-8fbe-468effed7f2b - FAILED-...

您可以尝试将 df 打印到输出中,而不是使用 {}.format(df)

print(df.to_string())

这对我有用:

#unlimited width - None
In [41]: pd.set_option('max_colwidth', None)

In [42]: df
Out[42]:
                                               failed_runs
0   296e62fb-1bc2-4e27-8d69-4a2267237698 - FAILED-GSN-INTO
1  92b15078-1fcc-41f0-bc20-d933becf23bf - FAILED-ESP2-INTO
2   b04460ef-32a7-403a-8fbe-468effed7f2b - FAILED-HLN-INTO

#reset to default width
In [43]: pd.reset_option('max_colwidth')

In [44]: df
Out[44]:
                                         failed_runs
0  296e62fb-1bc2-4e27-8d69-4a2267237698 - FAILED-...
1  92b15078-1fcc-41f0-bc20-d933becf23bf - FAILED-...
2  b04460ef-32a7-403a-8fbe-468effed7f2b - FAILED-...