简体   繁体   English

打印数据框而不会丢失格式

[英]print dataframe without losing format

How can I print a df without losing the format? 如何在不丢失格式的情况下打印df?

Lets say I have a df like this: 可以说我有一个像这样的df:

In: df
Out:

    TFs No Esenciales  Genes regulados  Genes Regulados Positivamente  Genes Regulados Negativamente  No Tentativo de genes a silenciar  No Real de genes a silenciar  No Tentativo de genes a inducir
146              YdeO               20                             18                              2                              2                               2                               0

But when I use print, It looses its format 但是当我使用打印时,它失去了格式

In: print (df)
Out:
        TFs No Esenciales  Genes regulados  Genes Regulados Positivamente  \
146              YdeO               20                             18   

     Genes Regulados Negativamente  No Tentativo de genes a silenciar  \
146                              2                                 2   

     No Real de genes a silenciar  No Tentativo de genes a inducir  \
146                            2                               0   

     No Real de genes a inducir  Balance de genes  Balance real de genes  
146                          0                 2                      2  

How can I use print, but keep the format? 如何使用打印,但保持格式?

My desired output is: 我想要的输出是:

In: print (df)
    Out:

    TFs No Esenciales  Genes regulados  Genes Regulados Positivamente  Genes Regulados Negativamente  No Tentativo de genes a silenciar  No Real de genes a silenciar  No Tentativo de genes a inducir
146              YdeO               20                             18                              2                              2                               2                               0

Per the docs , you can use the display.width option in Pandas. 根据文档 ,您可以在Pandas中使用display.width选项。

Something like the following should work (although you may have to increase the 1000 width value if it's still getting cut-off). 类似于以下内容的方法应该可以工作(尽管如果您仍然需要截断1000宽度值,则可能需要增加它)。

pd.set_option('display.width', 1000)
print(df)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM