我必须分析在给定期间使用应用程序的用户的活动,期间是开始和结束时间戳。我尝试了一个条形图,但我不知道如何在间隔中包含小时。 例:与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
我必须找到在specifc小时用户数量
[本博文](http://www.clowersresearch.com/main/gantt-charts-in-matplotlib/)给出了你想要的详细例子,请看看 –
甚至更好,[这里](https ://stackoverflow.com/questions/43367690/how-to-get-gantt-p lot-using-matplotlib) –