2025, Oct 23 23:00
How to show a pandas DataFrame index in marimo like Jupyter (use to_html for consistent display)
Learn why pandas hides the index in marimo and how to match Jupyter: render the DataFrame with to_html so the row index appears for reliable inspection.
How to make pandas show the index in marimo the same way it does in Jupyter
Context
When you create a pandas DataFrame in a Jupyter notebook and let the cell output render, you see the index alongside the columns. Running the same code in marimo can hide the index in the display. If you rely on the index for inspection or quick validation, that discrepancy is annoying and easy to miss.
Minimal example that highlights the difference
import pandas as p
p.DataFrame({"col1": ["a", "b", "c", "d"], "col2": ["e", "f", "g", "h"]})
In Jupyter, this renders with the index visible (0, 1, 2, 3). In marimo, running the same cell can hide the index in the output.
What’s going on
The same pandas object is being displayed in two environments with different frontends. In Jupyter, the default DataFrame display includes the index. In marimo, the index is hidden when you evaluate the same DataFrame cell directly. If you want the index visible in marimo, you need to take control of the rendering.
The fix
Render the DataFrame to HTML yourself and let marimo display that HTML. This makes the index appear in the output.
import pandas as p
import marimo as m
grid = p.DataFrame({"col1": ["a", "b", "c", "d"], "col2": ["e", "f", "g", "h"]})
m.Html(grid.to_html())
This approach preserves the DataFrame content and shows the index when viewed in marimo.
Why this matters
Index visibility affects how you verify joins, ordering, slicing, and alignment at a glance. If you’re moving between Jupyter and marimo, consistent rendering avoids false assumptions during exploratory analysis and code reviews.
Takeaways
If you need the index visible in marimo, render the DataFrame explicitly and display it via HTML. Use this pattern whenever display details are important and you want outcomes to match what you see in Jupyter.