DocumentationsearchSearchrocket_launchGet startedInstallationaddFundamentalsaddFirst stepsaddcodeDevelopConceptsaddAPI referenceremovePAGE ELEMENTSWrite and magicaddText elementsaddData elementsremovest.dataframest.data_editorst.column_configaddst.tablest.metricst.jsonChart elementsaddInput widgetsaddMedia elementsaddLayouts and containersaddChat elementsaddStatus elementsaddThird-party componentsopen_in_newAPPLICATION LOGICNavigation and pagesaddExecution flowaddCaching and stateaddConnections and secretsaddCustom componentsaddUtilitiesaddConfigurationaddTOOLSApp testingaddCommand lineaddTutorialsaddQuick referenceaddweb_assetDeployConceptsaddStreamlit Community CloudaddStreamlit in Snowflakeopen_in_newOther platformsaddschoolKnowledge baseFAQInstalling dependenciesDeployment issuesHome/Develop/API reference/Data elements/st.data_editorstarTipThis page only contains information on the st.data_editor API. For an overview of working with dataframes and to learn more about the data editor's capabilities and limitations, read Dataframes.
st.data_editorStreamlit VersionVersion 1.34.0Version 1.33.0Version 1.32.0Version 1.31.0Version 1.30.0Version 1.29.0Version 1.28.0Version 1.27.0Version 1.26.0Version 1.25.0Version 1.24.0Version 1.23.0Version 1.22.0Version 1.21.0Version 1.20.0Version 1.19.0Version 1.18.0Version 1.17.0Version 1.16.0Version 1.15.0Version 1.14.0Version 1.13.0Streamlit in SnowflakeDisplay a data editor widget.
The data editor widget allows you to edit dataframes and many other data structures in a table-like UI.

Warning
When going from st.experimental_data_editor to st.data_editor in
1.23.0, the data editor's representation in st.session_state was changed.
The edited_cells dictionary is now called edited_rows and uses a
different format ({0: {"column name": "edited value"}} instead of
{"0:1": "edited value"}). You may need to adjust the code if your app uses
st.experimental_data_editor in combination with st.session_state.

Function signature[source] st.data_editor(data, *, width=None, height=None, use_container_width=False, hide_index=None, column_order=None, column_config=None, num_rows="fixed", disabled=False, key=None, on_change=None, args=None, kwargs=None) Parameters

data
(pandas.DataFrame, pandas.Series, 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.

Note

Styles from pandas.Styler will only be applied to non-editable columns.
Mixing data types within a column can make the column uneditable.
Additionally, the following data types are not yet supported for editing:
complex, list, tuple, bytes, bytearray, memoryview, dict, set, frozenset,
fractions.Fraction, pandas.Interval, and pandas.Period.
To prevent overflow in JavaScript, columns containing datetime.timedelta
and pandas.Timedelta values will default to uneditable but this can be
changed through column configuration.




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.


hide_index
(bool or None)

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


column_order
(Iterable of str or None)

 
Specifies the display order of columns. This also affects which columns are
visible. For example, column_order=("col2", "col1") will display 'col2'
first, followed by 'col1', and will hide all other non-index columns. If
None (default), the order is inherited from the original data structure.


column_config
(dict or None)

 
Configures how columns are displayed, e.g. their title, visibility, type, or
format, as well as editing properties such as min/max value or step.
This needs to be a dictionary where each key is a column name and the value
is one of:

None to hide the column.
A string to set the display label of the column.
One of the column types defined under st.column_config, e.g.
st.column_config.NumberColumn("Dollar values”, format=”$ %d") to show
a column as dollar amounts. See more info on the available column types
and config options here.

To configure the index column(s), use _index as the column name.


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 or Iterable of str)

 
Controls the editing of columns. If True, editing is disabled for all columns.
If an Iterable of column names is provided (e.g., disabled=("col1", "col2")),
only the specified columns will be disabled for editing. If False (default),
all columns that support editing are editable.


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(pandas.DataFrame, pandas.Series, pyarrow.Table, numpy.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 pandas.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.data_editor(df)

favorite_command = edited_df.loc[edited_df["rating"].idxmax()]["command"]
st.markdown(f"Your favorite command is **{favorite_command}** 🎈")

Built with Streamlit 🎈Fullscreen open_in_new
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.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}** 🎈")

Built with Streamlit 🎈Fullscreen open_in_new
Or you can customize the data editor via column_config, hide_index, column_order, or disabled:

import pandas as pd
import streamlit as st

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.data_editor(
    df,
    column_config={
        "command": "Streamlit Command",
        "rating": st.column_config.NumberColumn(
            "Your rating",
            help="How much do you like this command (1-5)?",
            min_value=1,
            max_value=5,
            step=1,
            format="%d ⭐",
        ),
        "is_widget": "Widget ?",
    },
    disabled=["command", "is_widget"],
    hide_index=True,
)

favorite_command = edited_df.loc[edited_df["rating"].idxmax()]["command"]
st.markdown(f"Your favorite command is **{favorite_command}** 🎈")

Built with Streamlit 🎈Fullscreen open_in_new


Configuring columns
You can configure the display and editing behavior of columns in st.dataframe and st.data_editor via the Column configuration API. We have developed the API to let you add images, charts, and clickable URLs in dataframe and data editor columns. Additionally, you can make individual columns editable, set columns as categorical and specify which options they can take, hide the index of the dataframe, and much more.
Built with Streamlit 🎈Fullscreen open_in_newPrevious: st.dataframeNext: st.column_configforumStill have questions?Our forums are full of helpful information and Streamlit experts.HomeContact UsCommunity© 2024 Snowflake Inc.Cookie policy