Timo Timo - 7 months ago 84
Python Question

Pandas to_html() truncates string contents

I have a Python Pandas

object containing textual data. My problem is, that when I use
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

<table border="1" class="dataframe">
<tr style="text-align: right;">
<td> Lorem ipsum dolor sit amet, consectetur adipis...</td>

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