Important
This is an experimental feature. Experimental features and their APIs may change or be removed at any time. To learn more, click here.
Tip
This page only contains information on the st.experimental_data_editor
API. For a deeper dive into working with DataFrames and the data editor's capabilities, read Dataframes.
Display a data editor widget.
Display a data editor widget that allows you to edit DataFrames and many other data structures in a table-like UI.
Function signature[source] | |
---|---|
st.experimental_data_editor(data, *, width=None, height=None, use_container_width=False, num_rows="fixed", disabled=False, key=None, on_change=None, args=None, kwargs=None) | |
Parameters | |
data (pandas.DataFrame, pandas.Styler, pandas.Index, pyarrow.Table, numpy.ndarray, pyspark.sql.DataFrame, snowflake.snowpark.DataFrame, list, set, tuple, dict, or None) | The data to edit in the data editor. |
width (int or None) | Desired width of the data editor expressed in pixels. If None, the width will be automatically determined. |
height (int or None) | Desired height of the data editor expressed in pixels. If None, the height will be automatically determined. |
use_container_width (bool) | If True, set the data editor width to the width of the parent container. This takes precedence over the width argument. Defaults to False. |
num_rows ("fixed" or "dynamic") | Specifies if the user can add and delete rows in the data editor. If "fixed", the user cannot add or delete rows. If "dynamic", the user can add and delete rows in the data editor, but column sorting is disabled. Defaults to "fixed". |
disabled (bool) | An optional boolean which, if True, disables the data editor and prevents any edits. Defaults to False. This argument can only be supplied by keyword. |
key (str) | An optional string to use as the unique key for this widget. If this is omitted, a key will be generated for the widget based on its content. Multiple widgets of the same type may not share the same key. |
on_change (callable) | An optional callback invoked when this data_editor's value changes. |
args (tuple) | An optional tuple of args to pass to the callback. |
kwargs (dict) | An optional dict of kwargs to pass to the callback. |
Returns | |
(pd.DataFrame, pd.Styler, pyarrow.Table, np.ndarray, list, set, tuple, or dict.) | The edited data. The edited data is returned in its original data type if it corresponds to any of the supported return types. All other data types are returned as a pd.DataFrame. |
Examples
import streamlit as st import pandas as pd df = pd.DataFrame( [ {"command": "st.selectbox", "rating": 4, "is_widget": True}, {"command": "st.balloons", "rating": 5, "is_widget": False}, {"command": "st.time_input", "rating": 3, "is_widget": True}, ] ) edited_df = st.experimental_data_editor(df) favorite_command = edited_df.loc[edited_df["rating"].idxmax()]["command"] st.markdown(f"Your favorite command is **{favorite_command}** 🎈")(view standalone Streamlit app)You can also allow the user to add and delete rows by setting num_rows to "dynamic":
import streamlit as st import pandas as pd df = pd.DataFrame( [ {"command": "st.selectbox", "rating": 4, "is_widget": True}, {"command": "st.balloons", "rating": 5, "is_widget": False}, {"command": "st.time_input", "rating": 3, "is_widget": True}, ] ) edited_df = st.experimental_data_editor(df, num_rows="dynamic") favorite_command = edited_df.loc[edited_df["rating"].idxmax()]["command"] st.markdown(f"Your favorite command is **{favorite_command}** 🎈")(view standalone Streamlit app)