Error Mesage

hello i have problem like this picture, any solutions with my problem
Screenshot_2020-07-09 admin · Streamlit
code :

from apyori import apriori
rules = apriori(transactions, min_support = sp, min_confidence = cf, min_lift = lt, min_length = 2)
if st.button('Process'):
    aturan = list(rules)

def gen(aturan):
    lhs         = [tuple(result[2][0][0])[0] for result in aturan]
    rhs         = [tuple(result[2][0][1])[0] for result in aturan]
    supports    = [result[1] for result in aturan]
    confidences = [result[2][0][2] for result in aturan]
    lifts       = [result[2][0][3] for result in aturan]
    return list(zip(lhs, rhs, supports, confidences, lifts))
resultsinDataFrame = pd.DataFrame(gen(aturan), columns = ['Left Hand Side', 'Right Hand Side', 'Support', 'Confidence', 'Lift'])
st.write(resultsinDataFrame)

Hi @Ahmad_Muslim, welcome to the Streamliit community!

It’s important to remember that code runs top to bottom in Streamlit. The way you have your code set up, you are trying to call the resultsinDataFrame result before you’ve ensured that the st.button line has been pressed. If the button isn’t pressed, your code keeps moving on, and the you call gen(aturan) on an object that doesn’t exist.

I suspect your problem would go away if you move the last two lines of your code into the if st.button('Process'): line, so that they only run when the button is pressed.

1 Like

thank you for solutions it’s work for mee