Hi everyone,
I am trying to replace all values selected in a multiselect and replace them by information given in a text_input.
Unfortunately, only the last value is amended and I do not know why.
Steps to reproduce
`import streamlit as st
import pandas as pd
import openpyxl
from st_aggrid import AgGrid, GridUpdateMode, JsCode
from st_aggrid.grid_options_builder import GridOptionsBuilder
from datetime import datetime as dt
import calendar
uploaded_file = st.file_uploader(‘Please select the file’)
df = pd.read_excel(
io = uploaded_file,
engine = ‘openpyxl’,
sheet_name=‘Sheet1’,
)
df1 = pd.DataFrame(df, columns=[‘A’,‘B’,‘C’,‘D’,‘E’] )
st.write(df1)
#create a list removing all duplicates
dflist1 = pd.DataFrame(df1, columns=[‘B’])
dflist1 = dflist1[‘B’].unique().tolist()
#remove the empty value from the list
dflist1 = list(filter(None, dflist1))
replacedvalue = st.multiselect(
‘Select value replaced’,
dflist1, default=None)
list0=(dflist1)
list1=
for i in replacedvalue:
for k in list0:
if k==i:
test_radio=st.text_input('ticker ‘+ k + ’ to be replace by:’,‘Ticker only’,key=‘testlist’+k)
list1.append(test_radio)
df1 = df1.replace(to_replace=k, value= test_radio, regex=False)
AgGrid(df1)`
If applicable, please provide the steps we should take to reproduce the error or specified behavior.
Expected behavior:
I would like all variable selected being replaced in the dataframe from their respective value inserted in the inputbox.
Thanks in advance for your help
Actual behavior:
I expected all elements selected in the multiselect being replaced by the values entered on the different text_input.
By testing the code, you will realize that only the last one selected i the multiselect widget is replaced on the dataframe
Debug info
- Streamlit version: v1.10.0
- Python version: Python 3.6.15
- Using Jupiterlab
- OS version: windows 11
- Browser version: chome