gpt4 book ai didi

python - 如何绘制在很长一段时间内每小时发生的行数?

转载 作者:行者123 更新时间:2023-12-01 04:29:01 26 4
gpt4 key购买 nike

我有一个很大的 CSV 文件,如下所示:

ID,Time,Disposition,eventsID,Class,teamID
1,"2011-03-02 22:18:37",1,107,2,2
2,"2011-03-02 22:19:05",1,115,1,2
3,"2011-03-02 22:19:10",1,103,4,2
4,"2011-03-02 22:19:41",1,104,1,3
5,"2011-03-03 01:24:31",1,117,4,3

此数据跨越多个月。

我想显示每个年-月-日-小时发生的事件(行)数量的图(我不需要精确到分钟或秒)。

我有这个代码:

import pandas as pd
df = pd.read_csv('rtd_log.csv')
times = pd.DatetimeIndex(df.Time)
count_per_day = df.groupby([times.year, times.month, times.day, times.hour]).count()

这使得 count_per_day 看起来像:

2011  3  2  22    4
3 1 1

最后一列是计数。如何使用 count_per_day 结果绘制随时间变化的计数?

最佳答案

您可以使用DataFrame.plot()绘制图表。示例-

count_per_day.plot()

使用您添加的示例数据进行演示 -

enter image description here

关于python - 如何绘制在很长一段时间内每小时发生的行数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32664374/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com