2

I have a pandas dataframe that I want to display as a table in an html template. It works for the most part, but some of the strings in the dataframe are being truncated. I am using to_html() to convert my pandas dataframe to an html friendly table and tried using the col_space argument but it didn't seem to have any affect.

The python code:

options = dbi.getDBTables()  #returns a list of the names of available tables

table_headers = []

for table_name in options:
    table_name = str(table_name)
    df = dbi.selectDF("SELECT * FROM %s LIMIT 1" % table_name)  #gets the actual dataframe for each table name
    header = df.columns.values
    header = "<br>".join(header)
    table_headers.append(header)

header_dict = dict(zip(options,table_headers))
table_options = pandas.DataFrame(header_dict,index=[0])
table_options = table_options.to_html(classes=["table table-hover"],index=False,escape=False,col_space=400)  #changing the col_space does nothing.
search_dict = {'table_names':table_options}

The html code:

<div class="table-responsive">
   {{ table_names | safe }}
</div>

Picture of table with truncation occurring: enter image description here

How do you get pandas to stop truncating (shown as '...' in picture) content?

Much appreciated!

1 Answer 1

4

Just needed to set pandas.set_option('display.max_colwidth',100)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.