【发布时间】:2018-01-03 22:16:34
【问题描述】:
我必须分析在给定时间段内使用应用程序的用户的活动,时间段是开始和结束时间戳。我尝试使用条形图,但我不知道如何在间隔中包含小时数。 例如:uid=2 的用户使用位于 [18, 19, 20, 21] 的应用程序
我的数据框是这样的:
uid sex start end
1 0 2000-01-28 16:47:00 2000-01-28 17:47:00
2 1 2000-01-28 18:07:00 2000-01-28 21:47:00
3 1 2000-01-28 18:47:00 2000-01-28 20:17:00
4 0 2000-01-28 08:00:00 2000-01-28 10:00:00
5 1 2000-01-28 02:05:00 2000-01-28 02:30:00
6 0 2000-01-28 15:10:00 2000-01-28 18:04:00
7 0 2000-01-28 01:50:00 2000-01-28 03:00:00
df['hour_s'] = pd.to_datetime(df['start']).apply(lambda x: x.hour)
df['hour_e'] = pd.to_datetime(df['end']).apply(lambda x: x.hour)
uid sex start end hour_s hour_e
1 0 2000-01-28 16:47:00 2000-01-28 17:47:00 16 17
2 1 2000-01-28 18:07:00 2000-01-28 21:47:00 18 21
3 1 2000-01-28 18:47:00 2000-01-28 20:17:00 18 20
4 0 2000-01-28 08:00:00 2000-01-28 10:00:00 08 10
5 1 2000-01-28 02:05:00 2000-01-28 02:30:00 02 02
6 0 2000-01-28 15:10:00 2000-01-28 18:04:00 15 18
7 0 2000-01-28 01:50:00 2000-01-28 03:00:00 01 03
我必须在特定时间找到用户数
【问题讨论】:
-
This blog post给出了你想要的详细例子,请看一下
-
甚至更好,here
标签: python-3.x pandas matplotlib plotly data-science