5 Replies Latest reply on Aug 29, 2018 2:31 AM by Sasha Hanna

    Reproduce a Python code to a running sum

    luana otake

      Hello,

       

      I have this code in Python and I think it`s possible to change it in a running sum. I want to classify some numbers of clients to a group (A, B or C) and use a count to distribute then in classes.
      for example:

       

       

      I have 5 clients with the most values of discounts, then 15 with discounts above the median and 30 in the median.
      I want to classify then in Group A=5, group B=15 and Group C=30.

       

      This code can do this:

       

      count = 0

      for index, row in df_pos_filtro_ordenado.iterrows():

          count += 1

          #print(count , clientes_a)

          if (count <= clientes_a):

              df_pos_filtro_ordenado.set_value(index, 'GRUPO', 'A')

          elif (count <= clientes_b+clientes_a):

              df_pos_filtro_ordenado.set_value(index, 'GRUPO', 'B')

          elif ((count > clientes_b+clientes_a) & (count <= clientes_total)):

              df_pos_filtro_ordenado.set_value(index, 'GRUPO', 'C')

       

      I know Tabpy can do an integration with Python, but I think we can do this code in a calculated field.