st.dataframest.data_editor中配置列表列。

这是列表类值的默认列类型。目前列表列不可编辑。此命令需要在st.dataframest.data_editorcolumn_config参数中使用。

函数签名[source]

st.column_config.ListColumn(label=None, *, width=None, help=None, pinned=None)

参数

标签 (str 或 None)

显示在列顶部的标签。如果这是 None(默认),则使用列名。

宽度 ("small", "medium", "large", 或 None)

列的显示宽度。如果这是 None(默认值),列将根据单元格内容自动调整大小。否则,可以是以下之一:

  • "small": 75px 宽
  • "medium": 200px 宽
  • "large": 400px 宽

help (str or None)

一个可选的工具提示,当悬停在列标签上时会显示。如果这是None(默认值),则不显示工具提示。

pinned (bool or None)

列是否被固定。被固定的列将始终显示在左侧,无论用户滚动到哪里。如果这是None(默认值),Streamlit 将决定:索引列被固定,数据列不被固定。

示例

import pandas as pd
import streamlit as st

data_df = pd.DataFrame(
    {
        "sales": [
            [0, 4, 26, 80, 100, 40],
            [80, 20, 80, 35, 40, 100],
            [10, 20, 80, 80, 70, 0],
            [10, 100, 20, 100, 30, 100],
        ],
    }
)

st.data_editor(
    data_df,
    column_config={
        "sales": st.column_config.ListColumn(
            "Sales (last 6 months)",
            help="The sales volume in the last 6 months",
            width="medium",
        ),
    },
    hide_index=True,
)
forum

还有问题吗?

我们的 论坛 充满了有用的信息和Streamlit专家。