pandas
dataframe
HTML
data-conversion
Python

How can I display full non-truncated dataframe information in HTML when converting from Pandas dataframe to HTML?

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

If your pandas table looks truncated in HTML, the first thing to check is whether you are generating HTML with to_html() or simply looking at the notebook display representation. Those two paths are related, but they do not always behave the same way with respect to display options and truncation limits.

Direct to_html() Output

For explicit HTML generation, DataFrame.to_html() is the main API. If you want all rows and columns, pass max_rows=None and max_cols=None.

python
1import pandas as pd
2
3df = pd.DataFrame({
4    "name": ["Ada", "Grace", "Linus"],
5    "score": [98, 95, 91],
6    "notes": ["alpha", "beta", "gamma"]
7})
8
9html = df.to_html(max_rows=None, max_cols=None)
10print(html[:200])

That tells pandas not to apply row or column truncation for the generated table.

Display Options Matter in Interactive Environments

If the HTML you see comes from notebook rendering or another rich display hook, pandas display options can still matter. In that case, use a temporary option context:

python
1import pandas as pd
2
3with pd.option_context(
4    "display.max_rows", None,
5    "display.max_columns", None,
6    "display.max_colwidth", None
7):
8    html = df.to_html(max_rows=None, max_cols=None)

This is especially useful when long text columns are being shortened or when you want the full table for a one-off export without changing global settings for the rest of your session.

Column Width Is a Separate Issue

Sometimes the rows are not truncated, but the cell contents are. Long strings can still appear shortened depending on rendering and styling choices. If the problem is long text, control width and wrapping in HTML or CSS instead of only changing pandas row settings.

python
1html = df.to_html(
2    max_rows=None,
3    max_cols=None,
4    classes="full-table",
5    escape=True
6)

Then style the output:

html
1<style>
2  .full-table td {
3    white-space: normal;
4    word-break: break-word;
5  }
6</style>

Without CSS support, the browser may still make the table unpleasant to read even though pandas emitted all the data.

Exporting Large Tables

Showing the full HTML for a huge DataFrame is technically possible, but it may not be a good idea. Large tables create massive HTML strings, slow browsers down, and make debugging harder. In many real applications, the better choice is pagination, CSV download, or sampling.

Still, if the requirement is truly "do not truncate anything," to_html(max_rows=None, max_cols=None) is the right starting point.

Another useful distinction is between data completeness and visual usability. A table can contain every value and still feel unreadable without scrolling, wrapping, or filtering. Full output solves truncation, but it does not automatically solve presentation.

A Complete Example

python
1import pandas as pd
2
3df = pd.DataFrame({
4    "id": [1, 2],
5    "description": [
6        "A very long explanation that should remain visible in the HTML output.",
7        "Another detailed row that should not be shortened."
8    ]
9})
10
11with pd.option_context(
12    "display.max_rows", None,
13    "display.max_columns", None,
14    "display.max_colwidth", None
15):
16    html = df.to_html(max_rows=None, max_cols=None, escape=True)
17
18with open("table.html", "w", encoding="utf-8") as f:
19    f.write(html)

This produces a standalone HTML table string with no row or column truncation requested from pandas.

Common Pitfalls

  • Confusing DataFrame.to_html() output with the notebook's default HTML display behavior.
  • Setting only display.max_rows and forgetting column truncation or text width issues.
  • Generating huge HTML tables and then blaming truncation when the real issue is browser rendering or CSS overflow.
  • Turning off HTML escaping for convenience and accidentally rendering unsafe content.

Summary

  • Use df.to_html(max_rows=None, max_cols=None) to request full HTML output.
  • Use pd.option_context when interactive display settings are interfering.
  • Treat long-text rendering as a CSS problem, not just a pandas option problem.
  • Large full-table exports can be slow even when technically correct.
  • Distinguish between HTML generation and notebook display representation when debugging truncation.

Course illustration
Course illustration

All Rights Reserved.