Python code by duplicating the result of an array

Asked

Viewed 36 times

-3

I have a routine, in which, I need to create a matrix, which will be used to create some graphs.

The code is structured as follows::

3 lists for x, y, y

3 lists feeding the axes

  • 1 for client sets (X1);
  • 1 for the Intended Packages (Y1);
  • 1 for Delivered Packages (Y2);

3 Lists for the data.

all within a single list: dataplot[]

dataplot[x[X1[data]]y[Y1[data]]y[Y2[data]]]

And what controls the difference between the lists is VEHICLE.

I’ve come to that point:

def dataplot(x, y, z, w):
  dataplot = []
  for a in range(3):  
    x1 = []
    y1 = []
    w1 = []
    qntPlacas = len(selecao['Veículo'].unique())
    for b in range(qntPlacas):
      x0 = []
      y0 = []
      w0 = []
      for i in range(len(x)):
        if (z[i] == z[b]):
          x0.append(str(x[i]))
          y0.append(float(y[i].replace('.','').replace(',','.')))
          w0.append(float(w[i].replace('.','').replace(',','.')))
      x1.append(x0)
      y1.append(y0)
      w1.append(w0)
  dataplot.append(x1)
  dataplot.append(y1)
  dataplot.append(w1)
  return dataplot

dataplot = dataplot(selecao['Código Cliente'], selecao['Volume previsto'], selecao['Veículo'], selecao['Volume entregue'])
dataplot

The result is that it is printed from that code, it is:

[  
   [  
      ['8965'],  
      ['6769'],  
      ['5595', '3442'],  
      ['5595', '3442'],  # Duplicado  
      ['5027','89388','6566','89536','5485','1657','6939','6546','8876','1033','8410','9284','3709','5848','7307','89066'],  
      ['5027','89388','6566','89536','5485','1657','6939','6546','8876','1033','8410','9284','3709','5848','7307','89066']  # Duplicado
   ]
]

It is repeating the result when the board repeats.

And what should be printed is:

[  
   [  
      ['8965'],  
      ['6769'],  
      ['5595', '3442'],  
      
['5027','89388','6566','89536','5485','1657','6939','6546','8876','1033','8410','9284','3709','5848','7307','89066']  
   ]
]

Table for reference

Plates Client code Expected volume Volume delivered
PLAQUE 1 0001
PLAQUE 2 0002
PLAQUE 3 0003
PLAQUE 3 0005
PLAQUE 4 0005
PLAQUE 4 0006
PLAQUE 4 0007
PLAQUE 4 0008
PLAQUE 4 0009
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.