从 Pandas 数据帧转换为 HTML 时,如何在 HTML 中显示完整(未截断的)数据帧信息? [英] How can I display full (non-truncated) dataframe information in HTML when converting from Pandas dataframe to HTML?

查看:42
本文介绍了从 Pandas 数据帧转换为 HTML 时,如何在 HTML 中显示完整(未截断的)数据帧信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 DataFrame.to_html 函数将 Pandas 数据帧转换为 HTML 输出.当我将其保存到单独的 HTML 文件时,该文件会显示截断的输出.

例如,在我的 TEXT 列中,

df.head(1) 会显示

这部电影非常出色......

代替

这部电影在解构这一时期盛行的复杂社会情绪方面做出了出色的努力.

这种再现在大量 Pandas 数据帧的屏幕友好格式的情况下很好,但我需要一个 HTML 文件来显示包含在数据帧中的完整表格数据,也就是说,将显示后面的文本元素而不是之前的文本片段.

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

解决方案

display.max_colwidth 选项设置为 None(或 -11.0 版之前):

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

如果你设置了display.max_colwidth选项,信息将被完整显示:

I converted a Pandas dataframe to an HTML output using the DataFrame.to_html function. When I save this to a separate HTML file, the file shows truncated output.

For example, in my TEXT column,

df.head(1) will show

The film was an excellent effort...

instead of

The film was an excellent effort in deconstructing the complex social sentiments that prevailed during this period.

This rendition is fine in the case of a screen-friendly format of a massive Pandas dataframe, but I need an HTML file that will show complete tabular data contained in the dataframe, that is, something that will show the latter text element rather than the former text snippet.

How would I be able to show the complete, non-truncated text data for each element in my TEXT column in the HTML version of the information? I would imagine that the HTML table would have to display long cells to show the complete data, but as far as I understand, only column-width parameters can be passed into the DataFrame.to_html function.

解决方案

Set the display.max_colwidth option to None (or -1 before version 1.0):

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

set_option documentation

For example, in IPython, we see that the information is truncated to 50 characters. Anything in excess is ellipsized:

If you set the display.max_colwidth option, the information will be displayed fully:

这篇关于从 Pandas 数据帧转换为 HTML 时,如何在 HTML 中显示完整(未截断的)数据帧信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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