Hi! I’m trying to use the data_editor on a dataframe with column names which are integers. Upon editing the dataframe in the app, a key error is thrown. It seems like the problem is that st.session_state stores the column name as a string rather than an int, though it’s entirely possible I’m doing something foolish.
Upon editing a cell in the dataframe in the app the following error is thrown:
File “C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py”, line 552, in _run_script
exec(code, module.dict)
File “X:\st_test\test_interface.py”, line 20, in
new_distances = st.data_editor(distances,key=‘df’)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\streamlit\runtime\metrics_util.py”, line 356, in wrapped_func
result = non_optional_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\streamlit\elements\data_editor.py”, line 836, in data_editor
_apply_dataframe_edits(data_df, widget_state.value, dataframe_schema)
File “C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\streamlit\elements\data_editor.py”, line 359, in _apply_dataframe_edits
_apply_cell_edits(df, data_editor_state[“edited_rows”], dataframe_schema)
File “C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\streamlit\elements\data_editor.py”, line 260, in _apply_cell_edits
col_pos = df.columns.get_loc(col_name)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “C:\Users\user\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\indexes\base.py”, line 3654, in get_loc
raise KeyError(key) from err
Thank you for reporting this issue! I was able to repro the behavior and it seems like a bug to me. As such, I’ve submitted an issue on Streamlit’s GitHub repo:
Please upvote/thumbs up the issue if you’d like to see a fix prioritized.
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.