【问题标题】:Get pandas to print the complete string [duplicate]让熊猫打印完整的字符串[重复]
【发布时间】:2017-07-20 20:20:19
【问题描述】:

我有一个包含两列的 pandas 数据框 - 一列用于 id,另一列用于相应的标题。我正在为一些项目 id 设置数据框并显示结果数据框。这样做时,项目 id 显示正常,但相应的标题被截断并在几个字符后以 ... 结尾,如何让 pandas 在标题列中显示全文?

【问题讨论】:

  • 检查display.max_colwidth in docs (In [44]:)
  • @EdChum 不完全是我的想法。那个问题是当 OP 有多个列时,pandas 决定在打印时省略其中的一些列。在我的情况下,只有两列都被打印,但一列被截断

标签: python pandas


【解决方案1】:

你可以使用display.max_colwidth:

df = pd.DataFrame(np.array([[1,'aaa'],
                            [2, 'long string long string long string long string long string']]), columns=['id','title'])
print (df)
  id                                              title
0  1                                                aaa
1  2  long string long string long string long strin...

#temporaly display long text
with pd.option_context('display.max_colwidth', 100):
    print (df)
  id                                                        title
0  1                                                          aaa
1  2  long string long string long string long string long string

Documentation

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-01
    • 1970-01-01
    • 2017-02-02
    • 2020-12-21
    • 2021-08-07
    • 2012-11-28
    相关资源
    最近更新 更多