Not updating dataframe based on values from data_editor

UPDATE: I found my error. Note I’m using ==, as opposed to just one =, when assigning the value.

I’m trying to update a dataframe with data captured from the data_editor.

I’m subsetting a ā€˜main’ dataframe to the rows I want to show in the streamlit app. I use data_editor to show them and allow for updating of boolean columns. I have set the key = ā€˜data_editor’. I’m using a for loop to cycle through any data that was updated. Based on those that were updated I’m trying to update the ā€˜main’ dataframe.

Here’s the code I’m using to update the ā€˜main’ dataframe and then showing that subset. I’m showing the subset again on the screen for the purposes of testing. I’m thinking I should be seeing this subset with the updates made.

for key, value in st.session_state['data_editor']['edited_rows'].items():
    forindex = key
    print("key:", key, "value:", value)
    for updtd_col, new_val in value.items():
        print("\tUpdated Column:", updtd_col, "\tNew Value:", new_val)
        print("\t\tIndex:", Inbox_Site_df.iloc[forindex]['fileref'])
        Inbox_File_Level.loc[((Inbox_File_Level['site']== site_choice) & \
            (Inbox_File_Level['date'] == delivery_choice) & \
            (Inbox_File_Level['fileref'] == Inbox_Site_df.iloc[forindex]['fileref'])), updtd_col] == new_val


Inbox_File_Level.loc[(Inbox_File_Level['site']== site_choice) & (Inbox_File_Level['date'] == delivery_choice)]

In the above the updtd_col is the column indicated in the session state data_editor along with the new_val being the current value the user has selected. Here’s a screenshot of one item that was updated. You can see the name of the column here is ā€œStep_1_Check_csvā€ and the new_val = True. The Index is being used to help narrow filter the ā€˜main’ df to the row that should be updated.
image

Let me know what more would be helpful to provide.

UPDATE: I solved my problem. Notice I’m assigning the updated value using double =, ā€œ==ā€, not a single =. All is good.

Thank you if you’ve taken some time to try to comb through this for me.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.