pandas with Sumo traci: error raise valueError: Shape of passed values is (7, 1), indices imply (7, 7)

Viewed 9

hello I'm working with Traci libary in Sumo in python as i'm trying to get all trace information and put it in excel file
and i get this error when i pass the data to dataframe can anyone help me where is it wrong and how to fix it??

Traceback (most recent call last): dataset = pd.DataFrame(parkingList, index=None ,columns=columnnames) _check_values_indices_shape_match(values, index, columns) raise ValueError(f"Shape of passed values is {passed}, indices imply {implied}") ValueError: Shape of passed values is (7, 1), indices imply (7, 7)

here is my code :

   import traci
   import time
   import traci.constants as tc
   import pytz
   import datetime
   from random import randrange
   import pandas as pd

   def getdatetime():
    utc_now = pytz.utc.localize(datetime.datetime.utcnow())
    currentDT = utc_now.astimezone(pytz.timezone("Asia/Riyadh"))
    DATIME = currentDT.strftime("%Y-%m-%d %H:%M:%S")
    return DATIME

   sumoCmd = ["sumo", "-c", "cologne6to8.sumocfg"]
   traci.start(sumoCmd)

while traci.simulation.getMinExpectedNumber() > 0:
   
    traci.simulationStep();

 ParkingAreas = traci.parkingarea.getIDList();

    for i in range(0,len(ParkingAreas)):

      paid = ParkingAreas[i]
      lane = traci.parkingarea.getLaneID(ParkingAreas[i])
      startpos = traci.parkingarea.getStartPos(ParkingAreas[i])
      endpos =  traci.parkingarea.getEndPos(ParkingAreas[i])
      vehCount = traci.parkingarea.getVehicleCount(ParkingAreas[i])
       vehid = traci.parkingarea.getVehicleIDs(ParkingAreas[i])

  parkingList = [getdatetime(), paid, lane, startpos, endpos, vehCount, vehid]


   traci.close()

    #Generate Excel file
columnnames = ['dateandtime', 'parkingAreaID', 'Lane', 'start pos', 'end pos', 
 'numVehStops', 'vehIDsAtStop']

dataset = pd.DataFrame(parkingList,  index=None ,columns=columnnames)

dataset.to_excel("outputparking.xlsx", index=False)
time.sleep(5)
0 Answers
Related