Editable dataframes are here! ✍️

The doc page mentioned that

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?

That is the return value of experimental_data_editor().

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()
2 Likes

Good afternoon

Tell me, please, is there such a possibility that after adding a new row, the default values in all cells are not “None”, but 0?

Thank you in advance for your response!

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.

Hi all

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.

Any ideas, if this can be accomplished?

Thanks in advance! :slight_smile:

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.

1 Like

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?

You can specify the column type as CategoricalDtype using pandas:

1 Like

guys how to delete rows in this one ?

hey guys i’m also curios if its possible to add/delete columns in an existing data_editor just like the add/delete rows?

This is great guys !

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?

Not yet :frowning: Feel free to create a feature request for this here.

Btw. we recently moved st.data_editor out of experimental and released a lot of new configuration options. You can find out more in this blog post.

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.