在pandas数据框中完全打印很长的字符串 [英] Print very long string completely in pandas dataframe

查看:492
本文介绍了在pandas数据框中完全打印很长的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力处理看似非常简单的事情.我有一个包含很长字符串的pandas数据框.

I am struggling with the seemingly very simple thing.I have a pandas data frame containing very long string.

df = pd.DataFrame({'one' : ['one', 'two', 
      'This is very long string very long string very long string veryvery long string']})

现在,当我尝试打印相同的字符串时,我看不到完整的字符串,而只看到了字符串的一部分.

Now when I try to print the same, I do not see the full string I rather see only part of the string.

我尝试了以下选项

  • 使用print(df.iloc[2])
  • 使用to_html
  • 使用to_string
  • 其中一个stackoverflow答案建议将列宽增加 使用pandas显示选项,该方法也不起作用.
  • 我也不知道set_printoptions将如何帮助我.
  • using print(df.iloc[2])
  • using to_html
  • using to_string
  • One of the stackoverflow answer suggested to increase column width by using pandas display option, that did not work either.
  • I also did not get how set_printoptions will help me.

任何想法都值得赞赏.看起来很简单,但无法获得!

Any ideas appreciated. Looks very simple, but not able to get it!

推荐答案

您可以使用options.display.max_colwidth指定要在默认表示形式中查看的内容:

You can use options.display.max_colwidth to specify you want to see more in the default representation:

In [2]: df
Out[2]:
                                                 one
0                                                one
1                                                two
2  This is very long string very long string very...

In [3]: pd.options.display.max_colwidth
Out[3]: 50

In [4]: pd.options.display.max_colwidth = 100

In [5]: df
Out[5]:
                                                                               one
0                                                                              one
1                                                                              two
2  This is very long string very long string very long string veryvery long string

确实,如果您只想检查一个值,则可以通过访问它(作为标量,而不是像df.iloc[2]那样作为一行)来查看完整的字符串:

And indeed, if you just want to inspect the one value, by accessing it (as a scalar, not as a row as df.iloc[2] does) you also see the full string:

In [7]: df.iloc[2,0]    # or df.loc[2,'one']
Out[7]: 'This is very long string very long string very long string veryvery long string'

这篇关于在pandas数据框中完全打印很长的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆