【发布时间】:2019-05-27 15:01:12
【问题描述】:
我创建了一个充电模拟程序,可以模拟不同的电动汽车到达不同的充电站进行充电。
模拟完成后,程序会为充电站创建 CSV 文件,包括每小时统计数据和每天统计数据,首先,每小时统计数据 CSV 对我来说很重要。
我想为不同的车站绘制queue_length_per_hour(有多少辆车在排队等候,从 0 到 24 每小时)。
但问题是我不想包括所有站,因为它们太多了,所以我认为只有 3 个站就足够了。
我应该选择哪 3 个站点?我选择了 3 个车站,根据他们中哪个车站在白天访问的汽车最多(我可以在 24 小时看到),
正如您在代码中看到的那样,我使用了 pandas 的过滤方法,因此我可以根据 CSV 文件中第 24 小时访问次数最多的汽车选择前 3 个站点。
现在我有了前三个站点,现在我想绘制整个列 cars_in_queue_per_hour,不仅是第 24 小时,而且是从第 0 小时开始。
from time import sleep
import pandas as pd
import csv
import matplotlib.pyplot as plt
file_to_read = pd.read_csv('results_per_hour/hotspot_districts_results_from_simulation.csv', sep=";",encoding = "ISO-8859-1")
read_columns_of_file = file_to_read.columns
read_description = file_to_read.describe()
visited_cars_at_hour_24 = file_to_read["hour"] == 24
filtered = file_to_read.where(visited_cars_at_hour_24, inplace = True, axis=0)
top_three = (file_to_read.nlargest(3, 'visited_cars'))
# This pick top 3 station based on how many visited cars they had during the day
#print("Top Three stations based on amount of visisted cars:\n{}".format(top_three))
#print(type(top_three))
top_one_station = (top_three.iloc[0]) # HOW CAN I PLOT QUEUE_LENGTH_PER_HOUR COLUMN FROM THIS STATION TO A GRAPH?
top_two_station = (top_three.iloc[1]) # HOW CAN I ALSO PLOT QUEUE_LENGTH_PER_HOUR COLUMN FROM THIS STATION TO A GRAPH?
top_three_station = (top_three.iloc[2]) # AND ALSO THIS?
#print(top_one_station)
#print(file_to_read.where(file_to_read["name"] == "Vushtrri"))
#for row_index, row in top_three.iterrows():
# print(row)
# print(row_index)
# print(file_to_read.where(file_to_read["name"] == row["name"]))
# print(file_to_read.where(file_to_read["name"] == row["name"]).columns)
xlabel = []
for hour in range(0,25):
xlabel.append(hour)
ylabel = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] # how to append queue length per hour for the top 3 stations here?
plt.plot(xlabel,ylabel)
plt.show()
代码也可以在这个 repl.it 链接和 CSV 文件中找到:https://repl.it/@raxor2k/almost-done
【问题讨论】:
标签: python pandas csv matplotlib