I try to make an upload menu and make it into variable.
When the data have not been uploaded yet, the NameError occurs (there’s no problem when the data have been uploaded)
NameError: name 'dataframe' is not defined Traceback: File "c:\Users\xx\Desktop\yy\zz\poc_v3\.venv\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 552, in _run_script exec(code, module.__dict__) File "C:\Users\xx\Desktop\yy\zz\dinamic_ml\app.py", line 69, in <module> edited_dataframe = st.data_editor(dataframe)
I tried to handle it with try and except but doesn’t work.
Could you help me please?
# Setting the upload variabel uploaded_file = st.file_uploader("Choose a file to upload for training data", type="csv", help="The file will be used for training the Machine Learning") # Setting the upload options when there's file uploaded if uploaded_file is not None: try: # Can be used wherever a "file-like" object is accepted: dataframe = pd.read_csv(uploaded_file) st.write('Data Preview') st.write(dataframe) pr = dataframe.profile_report() st_profile_report(pr) except NameError: st.write("Please upload any data.")