Configure a number column in st.dataframe or st.data_editor.
This is the default column type for integer and float values. This command needs to be used in the column_config parameter of st.dataframe or st.data_editor. When used with st.data_editor, editing will be enabled with a numeric input widget.
Function signature[source] | |
---|---|
st.column_config.NumberColumn(label=None, *, width=None, help=None, disabled=None, required=None, pinned=None, default=None, format=None, min_value=None, max_value=None, step=None) | |
Parameters | |
label (str or None) | The label shown at the top of the column. If this is None (default), the column name is used. |
width ("small", "medium", "large", or None) | The display width of the column. If this is None (default), the column will be sized to fit the cell contents. Otherwise, this can be one of the following:
|
help (str or None) | An optional tooltip that gets displayed when hovering over the column label. If this is None (default), no tooltip is displayed. |
disabled (bool or None) | Whether editing should be disabled for this column. If this is None (default), Streamlit will decide: indices are disabled and data columns are not. If a column has mixed types, it may become uneditable regardless of disabled. |
required (bool or None) | Whether edited cells in the column need to have a value. If this is False (default), the user can submit empty values for this column. If this is True, an edited cell in this column can only be submitted if its value is not None, and a new row will only be submitted after the user fills in this column. |
pinned (bool or None) | Whether the column is pinned. A pinned column will stay visible on the left side no matter where the user scrolls. If this is None (default), Streamlit will decide: index columns are pinned, and data columns are not pinned. |
default (int, float, or None) | Specifies the default value in this column when a new row is added by the user. This defaults to None. |
format (str or None) | A printf-style format string controlling how numbers are displayed. This does not impact the return value. The following formatters are valid: %d, %e, %f, %g, %i, %u. You can also add prefixes and suffixes, e.g. "$ %.2f" to show a dollar prefix. If this is None (default), the numbers are not formatted. Number formatting from column_config always takes precedence over number formatting from pandas.Styler. |
min_value (int, float, or None) | The minimum value that can be entered. If this is None (default), there will be no minimum. |
max_value (int, float, or None) | The maximum value that can be entered. If this is None (default), there will be no maximum. |
step (int, float, or None) | The precision of numbers that can be entered. If this None (default), integer columns will have a step of 1 and float columns will have unrestricted precision. In this case, some floats may display like integers. Setting step for float columns will ensure a consistent number of digits after the decimal even without setting format. |
Examples
import pandas as pd import streamlit as st data_df = pd.DataFrame( { "price": [20, 950, 250, 500], } ) st.data_editor( data_df, column_config={ "price": st.column_config.NumberColumn( "Price (in USD)", help="The price of the product in USD", min_value=0, max_value=1000, step=1, format="$%d", ) }, hide_index=True, )
Still have questions?
Our forums are full of helpful information and Streamlit experts.