No need to compare the old and new dataframe to get the difference. Just use st.experimental_data_editor together with session state to access all edits, additions, and deletions.
Can anyone please explain a little bit more about how to get the changes in order to update the data in database?
That is the announcement, not the documentation. The actual documentation page on dataframes (linked in the announcement) has a section dedicated to getting the changed data, including sample code.
Just wanted to ask is there any way to access the edited dataframe, I tried adding/deleting columns and now i want to save this new dataframe but I am not able to ? is there any way?
Hi @lukasmasuch, how is it going with this one? I have seen version 1.21 changelog but didn’t see this fix mentioned. I was just wondering if it is coming along or if I should put effort into it myself or change some basic foundations of my app. Thank you for an otherwise awesome feature!
@Mianen Just for posterity, if anyone wants a different workaround right now, you can use experimental rerun and a flag in session state to rebuild the data editor automatically. In effect, automate that second load so the user doesn’t see or “feel” it.
import streamlit as st
import pandas as pd
if 'df' not in st.session_state:
st.session_state.df = pd.DataFrame({'A':[1,2,3,4],'B':[1,2,3,4]})
st.session_state.rerun = False
def rerun():
st.session_state.rerun = True
st.session_state.df = st.experimental_data_editor(st.session_state.df, on_change=rerun)
if st.session_state.rerun:
st.session_state.rerun = False
st.experimental_rerun()
That’s not inherently available at this time. You would have to manipulate the data on the backend and push it as a new baseline for the data editor.
You will have one problem though that new rows don’t actually show up right away: you have to edit some value somewhere in the dataframe for any pending new rows to push through. (That could be entering some data within a new row, or editing something on a different row.) If you add a bunch of rows and keep escaping out without entering/editing any data, then you will only see the new rows on the front end and they won’t be returned by a widget yet.
I am trying to create an editable dataframe where one column is categorical and therefore offers choices as a dropdown once clicked. Additionally, and this is my current problem, I am trying to offer the user to input his own free text in the same column if no choice of the dropdown fits.
Once I convert the column to categorical the text input function does not work anymore.
I don’t think there is a way under the current version. They have added column controls coming out in Version 1.23 but I believe you will have the same restriction, effectively.
You could provide a separate input widget for a user to add to the list of categories, in effect using an external source to expand the options for the drop down.
Thanks for your reply! Do you happen to know, how I can define choice options for a category column? Right now I only manage to make the choice options the unique values that are available in the column. Is there any way to define the choice options by a list without having each option present in the column?
This is so cool. This is exactly what I’ve been looking for for a while, and just found it.
Bulk-editing by dragging the handle on a cell (similar to Excel):
I don’t see this functionality when I’m trying it out. I see it in some demos and not others. In my app (st version 1.23.1) I don’t see it. Was it removed in an update, or is there a config you have to set up to make it work?
I think the fill handle gets deactivated when it is used with a touch device (e.g. mobile device) since this feature is currently causing some trouble in relation to usage via touch. Are you using a touch device?
There is feature to drag cells to repeat same values when needed. But there is not option to undo that on the go. Or if there is anyone plz reply here.
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.