Py学习  »  Python

字符串到python dataframe的concat正在修剪值[duplicate]

Sireesha Malla • 4 年前 • 372 次点击  

我使用 DataFrame.to_html 功能。当我将它保存到一个单独的html文件中时,该文件显示被截断的输出。

例如,在我的文本列中,

df.head(1) 将显示

这部电影是一部出色的作品。。。

而不是

这部电影是解构这一时期盛行的复杂社会情绪的杰出作品。

对于屏幕友好格式的大型pandas数据帧,这种格式副本很好,但我需要一个html文件来显示数据帧中包含的完整表格数据,即显示后一个文本元素而不是前一个文本片段的内容。

如何才能在信息的html版本中显示文本列中每个元素的完整、未截断的文本数据?我可以想象html表必须显示长单元格才能显示完整的数据,但据我所知,只有列宽参数可以传递到 DataFrame.to_html格式 功能。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/50952
 
372 次点击  
文章 [ 3 ]  |  最新文章 4 年前
Karl Adler
Reply   •   1 楼
Karl Adler    5 年前

pd.set_option('display.max_columns', None) 设置显示的最大列数,选择 pd.set_option('display.max_colwidth', -1) 设置每个字段的最大宽度。

为了达到我的目的,我编写了一个小的helper函数来完全打印大数据帧,而不影响其余代码,它还重新格式化浮点数并设置虚拟显示宽度。您可以在您的用例中采用它。

def print_full(x):
    pd.set_option('display.max_rows', len(x))
    pd.set_option('display.max_columns', None)
    pd.set_option('display.width', 2000)
    pd.set_option('display.float_format', '{:20,.2f}'.format)
    pd.set_option('display.max_colwidth', -1)
    print(x)
    pd.reset_option('display.max_rows')
    pd.reset_option('display.max_columns')
    pd.reset_option('display.width')
    pd.reset_option('display.float_format')
    pd.reset_option('display.max_colwidth')
rafaelvalle user7579768
Reply   •   2 楼
rafaelvalle user7579768    6 年前
pd.set_option('display.max_columns', None)  

id (第二个参数)可以完全显示列。

Simon behzad.nouri
Reply   •   3 楼
Simon behzad.nouri    5 年前

设置 display.max_colwidth 选择 -1 :

pd.set_option('display.max_colwidth', -1)

set_option docs

例如,在iPython中,我们看到信息被截断为50个字符。任何多余的都被省略:

enter image description here

如果你设置 选项,信息将完全显示:

enter image description here