Need help to correct my code to get the co2 and fuel
I have this xml how can i get the mean for fuel_abs and co2_abs
<tripinfo id="vehicle_3" depart="0.00" departLane="-E11_0" departPos="5.10" departSpeed="0.00" departDelay="0.00" arrival="30.00" arrivalLane="E1_0" arrivalPos="92.80" arrivalSpeed="12.12" duration="30.00" routeLength="189.53" waitingTime="0.00" waitingCount="0" stopTime="0.00" timeLoss="14.02" rerouteNo="0" devices="tripinfo_vehicle_3 emissions_vehicle_3" vType="type_0" speedFactor="0.94" vaporized="">
<emissions CO_abs="2219.290354" CO2_abs="87498.406338" HC_abs="12.109533" PMx_abs="1.438844" NOx_abs="35.498019" fuel_abs="27908.615964" electricity_abs="0"/>
</tripinfo>
<tripinfo id="vehicle_4" depart="0.00" departLane="-E8_0" departPos="5.10" departSpeed="0.00" departDelay="0.00" arrival=&q开发者_Go百科uot;39.00" arrivalLane="E11_0" arrivalPos="92.80" arrivalSpeed="14.91" duration="39.00" routeLength="394.90" waitingTime="0.00" waitingCount="0" stopTime="0.00" timeLoss="12.32" rerouteNo="0" devices="tripinfo_vehicle_4 emissions_vehicle_4" vType="type_0" speedFactor="1.09" vaporized="">
<emissions CO_abs="1997.757215" CO2_abs="119332.147653" HC_abs="11.498344" PMx_abs="1.640304" NOx_abs="44.809512" fuel_abs="38062.107246" electricity_abs="0"/>
</tripinfo>
My functions cant get the access to the right data tag(emissions) so it will not calculate
def get_average_CO2():
xtree = et.parse("./scenario/sample.tripinfo.xml")
xroot = xtree.getroot()
rows = []
for node in xroot:
co2_emission = node.attrib.get("CO2_abs")
rows.append({"co2_emission": co2_emission})
columns = ["co2_emission"]
co2_emission = pd.DataFrame(rows, columns=columns).astype("float64")
return co2_emission["co2_emission"].mean()
def get_average_fuel():
xtree = et.parse("./scenario/sample.tripinfo.xml")
xroot = xtree.getroot()
rows = []
for node in xroot:
fuel_cons = node.attrib.get("fuel_abs")
rows.append({"fuel_cons": fuel_cons})
columns = ["fuel_cons"]
fuel_cons = pd.DataFrame(rows, columns=columns).astype("float64")
return fuel_cons["fuel_cons"].mean()
精彩评论