I want to create an empty dataset and add rows to that dataset. Then I want to view the dataset elsewhere.
I wrote a function for this and I am able to add a new record with the help of this function. I assign the dataset to the ‘before’ variable after each new record is added.
@st.cache(allow_output_mutation=True, persist = True)
def beforeSTable(col, nan, nofr, pfr, dqs):
global before
before = pd.DataFrame(columns=["Column", "Null Records", "Out of Format Records", "Proper Format Records", "Column DQ Score(%)"])
before.loc[len(before)] = [col, nan, nofr, pfr, dqs]
return before
.
.
.
if table == "'Before' Summary Table":
if insert:
before = beforeSTable(selected_column, nanCount, NOFR, PFR, dq_score)
st.success("Values have been added to 'Before' Summary Table.")
.
.
.
if task == "Review Summary Report and Download Adjusted Data":
st.write("'Before' Summary Table")
st.dataframe(before.style.format({"Column DQ Score(%)": '{:,.2f}'}))
However, when I want to view the dataset, I get the error that the ‘before’ variable is not defined.
NameError: name 'before' is not defined
Traceback:
File "c:\users\beytullah.goyem\anaconda3\envs\streamlit\lib\site-packages\streamlit\script_runner.py", line 338, in _run_script
exec(code, module.__dict__)
File "C:\Users\beytullah.goyem\PycharmProjects\dataqtor\home.py", line 2036, in <module>
st.dataframe(before.style.format({"Column DQ Score(%)": '{:,.2f}'}))
I know why I am getting this error. The code block I assigned the dataset to the ‘before’ variable falls outside the code block I want to display the dataset in. That’s why it doesn’t recognize the ‘before’ variable when I want to display the dataset.
Isn’t there a way to call the internally created variable external? I hope I was able to explain my problem.