You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在marimo执行单元格时显示DataFrame索引?

Marimo中显示Pandas DataFrame索引的方法

marimo默认会隐藏Pandas DataFrame的索引,但你可以通过两种方式开启显示:

1. 为单个DataFrame临时显示索引

使用marimo的display函数,显式指定index=True参数:

import marimo as mo
import pandas as pd

df = pd.DataFrame({"col1": ["a", "b", "c", "d"], "col2": ["e", "f", "g", "h"]})
mo.display(df, index=True)

2. 全局设置默认显示所有DataFrame的索引

在notebook的开头设置Pandas的全局显示选项,之后所有DataFrame都会默认显示索引:

import pandas as pd

pd.set_option('display.show_index', True)
df = pd.DataFrame({"col1": ["a", "b", "c", "d"], "col2": ["e", "f", "g", "h"]})
df  # 此时会显示索引

内容的提问来源于stack exchange,提问作者Laurent

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 15:15:59