pandas to_html()截断字符串内容 [英] Pandas to_html() truncates string contents
问题描述
我有一个包含文本数据的Python Pandas DataFrame
对象。我的问题是,当我使用 to_html()
函数,它会截断输出中的字符串。
例如:
import pandas
df = pandas.DataFrame({'text':['Lorem ipsum dolor sit amet,consectetur adipiscing elit。']})
print(df.to_html())
被截断为 adapis ...
< table border = 1class =dataframe>
< thead>
< tr style =text-align:right;>
< th>< / th>
< th>文本< / th>
< / tr>
< / thead>
< tbody>
< tr>
< th> 0< / th>
< td> Lorem ipsum dolor sit amet,consectetur adipis ...< / td>
< / tr>
< / tbody>
< / table>
有一个关于SO的相关问题,但它使用占位符和搜索/替换功能来后处理HTML ,我想避免:
<有没有更简单的解决方案来解决这个问题?我找不到文档中的任何相关内容。
你看到的只是为了显示目的而截断输出的熊猫。
默认的 max_colwidth
值是50,这是您所看到的。
您可以将此值设置为任何您想要的值,或者您可以将其设置为-1,从而有效地将其关闭:
pd.set_option('display.max_colwidth',-1)
虽然我会建议因此,最好将它设置为可以在控制台或ipython中轻松显示的内容。
可在此处找到选项列表: http://pandas.pydata.org/pandas-docs/stable/options.html
I have a Python Pandas DataFrame
object containing textual data. My problem is, that when I use to_html()
function, it truncates the strings in the output.
For example:
import pandas
df = pandas.DataFrame({'text': ['Lorem ipsum dolor sit amet, consectetur adipiscing elit.']})
print (df.to_html())
The output is truncated at adapis...
<table border="1" class="dataframe">
<thead>
<tr style="text-align: right;">
<th></th>
<th>text</th>
</tr>
</thead>
<tbody>
<tr>
<th>0</th>
<td> Lorem ipsum dolor sit amet, consectetur adipis...</td>
</tr>
</tbody>
</table>
There is a related question on SO, but it uses placeholders and search/replace functionality to postprocess the HTML, which I would like to avoid:
Is there a simpler solution to this problem? I could not find anything related from the documentation.
What you are seeing is pandas truncating the output for display purposes only.
The default max_colwidth
value is 50 which is what you are seeing.
You can set this value to whatever you desire or you can set it to -1 which effectively turns this off:
pd.set_option('display.max_colwidth', -1)
Although I would advise against this, it would be better to set it to something that can be displayed easily in your console or ipython.
A list of the options can be found here: http://pandas.pydata.org/pandas-docs/stable/options.html
这篇关于 pandas to_html()截断字符串内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!