pandas DataFrame.to_string()从列中截断字符串

2024-06-16 09:21:59 发布

您现在位置:Python中文网/ 问答频道 /正文

当我试图使用tou string从dataframe输出列时,它会截断该列的输出。

print gtf_df.ix[:1][['transcript_id','attributes']].to_string(header=False,index=False)

Out: ' CUFF.1.1  gene_id "CUFF.1"; transcript_id "CUFF.1.1"; FPKM '

print gtf_df.ix[:1]['attributes'][0]

Out: 'gene_id "CUFF.1"; transcript_id "CUFF.1.1"; FPKM "1670303.8168650887"; frac "1.000000"; conf_lo "0.000000"; conf_hi "5010911.450595"; cov "9658.694354";'

关于如何解决这个问题有什么想法吗? 谢谢!


Tags: idfalsedataframedfstringconfoutattributes
2条回答

使用__repr__to_string列默认被截断为50个字符。在大于0.13.1的Pandas版本中,这可以使用pandas.set_printoptions()来控制:

In [64]: df
Out[64]:
                                                   A    B
a  this is a very long string, longer than the defau  bar
b                                                foo  baz

In [65]: pandas.set_printoptions(max_colwidth=100)

In [66]: df
Out[66]:
                                                                      A    B
a  this is a very long string, longer than the default max_column width  bar
b                                                                   foo  baz

在较新版本的Pandas中,请改用此选项:

pd.options.display.max_colwidth = 100

熊猫改变了设置此选项的方式。这是current documentation

pd.set_option('display.max_colwidth', 100)

查看文档以了解其他好的文档,如:

pd.set_option('display.max_rows', 999)

相关问题 更多 >