Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

Fix: truncate dataframes rows, columns in output (#341)

Akshay Agrawal8dfe98d0b336
diff --git a/marimo/_output/formatters/pandas_formatters.py b/marimo/_output/formatters/pandas_formatters.py
index 259be7d657..d563ae3968 100644
--- a/marimo/_output/formatters/pandas_formatters.py
+++ b/marimo/_output/formatters/pandas_formatters.py
@@ -15,20 +15,28 @@ class PandasFormatter(FormatterFactory):
def register(self) -> None:
import pandas as pd
+ pd.set_option("display.max_rows", 10)
+ pd.set_option("display.max_columns", 20)
+
from marimo._output import formatting
@formatting.formatter(pd.DataFrame)
def _show_dataframe(df: pd.DataFrame) -> tuple[str, str]:
+ max_rows = pd.get_option("display.max_rows")
+ max_columns = pd.get_option("display.max_columns")
# Flatten the HTML to avoid indentation issues when
# interpolating into other HTML/Markdown with an f-string
return (
"text/html",
- flatten_string(df.to_html()),
+ flatten_string(
+ df.to_html(max_rows=max_rows, max_cols=max_columns)
+ ),
)
@formatting.formatter(pd.Series)
def _show_series(series: pd.Series[Any]) -> tuple[str, str]:
+ max_rows = pd.get_option("display.max_rows")
return (
"text/html",
- flatten_string(series.to_frame().to_html()),
+ flatten_string(series.to_frame().to_html(max_rows=max_rows)),
)