pandas
dataframe
string manipulation
data visualization
python

Print very long string in Pandas dataframe

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

Introduction

Pandas truncates long strings by default so tables remain readable in terminals and notebooks. That is helpful for large datasets, but it gets in the way when you need to inspect the full contents of a text column. The fix is usually to adjust display options temporarily rather than permanently changing how the whole process prints DataFrames.

Core Sections

Why Pandas Truncates Long Strings

Pandas tries to keep tabular output compact. If a column contains long text such as descriptions, JSON blobs, or log lines, the printed representation often shows only part of the value followed by an ellipsis.

Example:

python
1import pandas as pd
2
3df = pd.DataFrame({
4    "id": [1, 2],
5    "text": [
6        "This is a very long string that would normally be truncated by pandas display settings.",
7        "Another extremely long string used for debugging output in a dataframe column."
8    ]
9})
10
11print(df)

By default, the full text may not be shown.

Show Full Column Width

The most direct fix is to raise or disable the maximum column width limit:

python
1import pandas as pd
2
3pd.set_option("display.max_colwidth", None)
4
5print(df)

Setting None tells Pandas not to truncate column text by width.

Use a Temporary Display Context

If you do not want to change global settings for the whole process, use option_context:

python
1import pandas as pd
2
3with pd.option_context("display.max_colwidth", None):
4    print(df)

This is usually the best choice in notebooks, scripts, and tests because it avoids side effects in later cells or functions.

Show One Specific Value Fully

Sometimes you do not need the whole DataFrame printed. You only need one cell:

python
print(df.loc[0, "text"])

Or for all values in a single column:

python
for value in df["text"]:
    print(value)
    print("-" * 40)

This is often clearer than trying to inspect a very wide table.

Control Row and Frame Width Too

Long strings are not the only thing affecting output. Row count and frame width also matter.

python
1import pandas as pd
2
3with pd.option_context(
4    "display.max_colwidth", None,
5    "display.max_rows", None,
6    "display.expand_frame_repr", False
7):
8    print(df)

expand_frame_repr=False helps prevent line wrapping across multiple terminal lines in some environments.

Jupyter Notebook Display

In notebooks, print(df) and plain df display can behave differently. Sometimes HTML rendering still feels constrained. If needed, render a single column explicitly:

python
1from IPython.display import display
2
3with pd.option_context("display.max_colwidth", None):
4    display(df)

If the notebook still feels cramped, selecting only the text column can make inspection easier.

Export for External Inspection

If the strings are extremely long, printing may not be the best interface at all. Exporting can be more practical:

python
df.to_csv("debug_output.csv", index=False)

Or write the specific column to a text file:

python
with open("texts.txt", "w", encoding="utf-8") as f:
    for value in df["text"]:
        f.write(value + "\n\n")

This is often the right debugging move for logs, prompts, or generated text samples.

Reset Display Options When Needed

If you changed options globally and want to revert:

python
pd.reset_option("display.max_colwidth")

This is useful in shared notebooks or longer-running analysis sessions where broad display changes can surprise later code.

Choose the Right Inspection Method

A practical rule:

  1. use option_context for temporary full display
  2. print one cell when you need one exact value
  3. export when the data is too wide for comfortable terminal viewing

That keeps debugging focused instead of turning every DataFrame print into a giant wall of text.

Common Pitfalls

  • Setting global display options and forgetting they affect later notebook cells or scripts.
  • Trying to inspect very large text columns by printing the full DataFrame when one cell would be clearer.
  • Confusing terminal width limits with Pandas truncation settings.
  • Assuming notebook HTML display behaves exactly like plain print(df).
  • Using full-width display on huge datasets and making output harder to read instead of easier.

Summary

  • Pandas truncates long strings by default to keep table output manageable.
  • Use display.max_colwidth = None to show full text when needed.
  • Prefer pd.option_context for temporary display changes.
  • Print individual cells or columns when that is clearer than printing the whole frame.
  • Export very long text to files when console or notebook display becomes impractical.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design

All Rights Reserved.