mercredi 2 octobre 2019

how do i loop over a data frame where the first row value is maximum and dynamically keep updating the iterables in the for loop

I have a data frame given below. this data frame just shows 1 car(QAZX) that carries a parcel of different volume across cities. The different cities are given in 1,2,3,4,5,6......... The first row is my most important row as it is containing the highest value of volume carried by my car. I have 55 such cars.(QAZX, MNGH,NBTR, CVRT.....) I wanna loop over all of them. Different cars have different no lists of cities carrying different volume.

I wanna write a for loop such that I can loop over them and dynamically keep updating my list of iterables without having to change my car name and iterables for each one of it. Below is my dataset:

Car Name    Volume  Route
QAZX        3418    [4, 5, 6, 7]
QAZX        2617    [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
QAZX        2430    [1, 2, 3, 4, 5, 6, 7]
QAZX        1871    [1, 2, 3]
QAZX        1442    [1, 2, 3, 4]
QAZX        1292    [4, 5, 6, 7]
QAZX        1039    [11, 12, 13, 14, 15]
QAZX        1036    [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
QAZX         892    [1, 2, 3]
QAZX         692    [1, 2, 3, 4]
QAZX         99     [1, 2, 3, 4, 5, 6, 7]
QAZX         54     [1, 2, 3]


import numpy as np
import pandas as pd

car = car[car.Car_Name == QAZX]
car = car['Route'].to_frame().argmax().values
print(car)
for vol,row in [car[car.Route].iterrows()]:
print(vol)
print(row)

I got : unhashable type: 'list' and Df has no attribute argmax

Aucun commentaire:

Enregistrer un commentaire