添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
star

Tip

Learn more in our Dataframes guide and check out our tutorial, Get dataframe row-selections from users .

Display a dataframe as an interactive table.

This command works with dataframes from Pandas, PyArrow, Snowpark, and PySpark. It can also display several other types that can be converted to dataframes, e.g. numpy arrays, lists, sets and dictionaries.

Function signature [source]

st.dataframe(data=None, width=None, height=None, *, use_container_width=False, hide_index=None, column_order=None, column_config=None, key=None, on_select="ignore", selection_mode="multi-row")

Parameters
(pandas.DataFrame, pandas.Series, pandas.Styler, pandas.Index, pyarrow.Table, numpy.ndarray, pyspark.sql.DataFrame, snowflake.snowpark.dataframe.DataFrame, snowflake.snowpark.table.Table, Iterable, dict, or None)

The data to display.

If data is a pandas.Styler , it will be used to style its underlying pandas.DataFrame . Streamlit supports custom cell values and colors. It does not support some of the more exotic pandas styling features, like bar charts, hovering, and captions.

width (int or None)

Desired width of the dataframe expressed in pixels. If width is None (default), Streamlit sets the dataframe width to fit its contents up to the width of the parent container. If width is greater than the width of the parent container, Streamlit sets the dataframe width to match the width of the parent container.

height (int or None)

Desired height of the dataframe expressed in pixels. If height is None (default), Streamlit sets the height to show at most ten rows. Vertical scrolling within the dataframe element is enabled when the height does not accomodate all rows.

use_container_width (bool)

Whether to override width with the width of the parent container. If use_container_width is False (default), Streamlit sets the dataframe's width according to width . If use_container_width is True , Streamlit sets the width of the dataframe to match the width of the parent container.

hide_index (bool or None)

Whether to hide the index column(s). If hide_index is None (default), the visibility of index columns is automatically determined based on the data.

column_order (Iterable of str or None)

The ordered list of columns to display. If column_order is None (default), Streamlit displays all columns in the order inherited from the underlying data structure. If column_order is a list, the indicated columns will display in the order they appear within the list. Columns may be omitted or repeated within the list.

For example, column_order=("col2", "col1") will display "col2" first, followed by "col1" , and will hide all other non-index columns.

column_config (dict or None)

Configuration to customize how columns display. If column_config is None (default), columns are styled based on the underlying data type of each column.

Column configuration can modify column names, visibility, type, width, or format, among other things. column_config must be a dictionary where each key is a column name and the associated value is one of the following:

  • None : Streamlit hides the column.
  • A string: Streamlit changes the display label of the column to the given string.
  • A column type within st.column_config : Streamlit applies the defined configuration to the column. For example, use st.column_config.NumberColumn("Dollar values”, format=”$ %d") to change the displayed name of the column to "Dollar values" and add a "$" prefix in each cell. For more info on the available column types and config options, see Column configuration .
  • To configure the index column(s), use _index as the column name.

    (str)

    An optional string to use for giving this element a stable identity. If key is None (default), this element's identity will be determined based on the values of the other parameters.

    Additionally, if selections are activated and key is provided, Streamlit will register the key in Session State to store the selection state. The selection state is read-only.

    on_select ("ignore" or "rerun" or callable)

    How the dataframe should respond to user selection events. This controls whether or not the dataframe behaves like an input widget. on_select can be one of the following:

  • "ignore" (default): Streamlit will not react to any selection events in the dataframe. The dataframe will not behave like an input widget.
  • "rerun" : Streamlit will rerun the app when the user selects rows or columns in the dataframe. In this case, st.dataframe will return the selection data as a dictionary.
  • A callable : Streamlit will rerun the app and execute the callable as a callback function before the rest of the app. In this case, st.dataframe will return the selection data as a dictionary.
  • "multi-row" (default): Multiple rows can be selected at a time.
  • "single-row": Only one row can be selected at a time.
  • "multi-column": Multiple columns can be selected at a time.
  • "single-column": Only one column can be selected at a time.
  • An Iterable of the above options: The table will allow selection based on the modes specified.
  • When column selections are enabled, column sorting is disabled.

    Returns

    (element or dict)

    If on_select is "ignore" (default), this method returns an internal placeholder for the dataframe element that can be used with the .add_rows() method. Otherwise, this method returns a dictionary-like object that supports both key and attribute notation. The attributes are described by the DataframeState dictionary schema.

    Examples

    import streamlit as st import pandas as pd import numpy as np df = pd.DataFrame(np.random.randn(50, 20), columns=("col %d" % i for i in range(20))) st.dataframe(df) # Same as st.write(df)