[Python] Different Variable in while loop

Discussão em 'Python' iniciado por Stack, Maio 14, 2025.

  1. Stack

    Stack Membro Participativo

    Is it possible to save a value on different variable in a while loop?

    For example this is my code

    category = [] #differs depending on the input of user
    var1 = []
    var2 = []
    var3 = []

    i = []
    max_count = len(category)
    while i < max_count:
    for ms_division in market_share_division:
    ms_division_df = df3[df3['Geography'] == ms_division]
    ms_product_df = ms_division_df[ms_division_df['Product'] == category]
    ms_df_4 = ms_product_df[ms_product_df['Time Period'].str.contains('L 4', na=False, case=False)]
    ms_df_4 = ms_df_4.head(1)
    if len(ms_df_4)>0:
    ms_df_row_1 = ms_df_4.iloc[0]
    var1.append(ms_df_row_1['Dollar Sales'])


    But what i want to do is after the 1st loop, I want to save the next data on the var2 and so on and so forth.

    Continue reading...

Compartilhe esta Página