我有这样一个数据集
users b kk timstamp product
8fa683e59c02c04cb781ac689686db07 start 1.46276E+12 00:00.0 55107008
335644267c1d5f04eaea7bc6f51b1861 start 1.46276E+12 00:00.0 55107008
ca3071aad676bc963795a2b09635cdf0 stop 1.46277E+12 00:00.0 55107008
17412dec7d3d02c9b0b1c3d1c3571c5c stop 1.46276E+12 00:00.0 10655437
f81167c854f1a0c86cab6188f9995824 start 1.46276E+12 00:00.1 55107008
17412dec7d3d02c9b0b1c3d1c3571c5c start 1.46276E+12 00:00.1 10655437
a2659df45c8d05f326225fa5b1063ac9 start 1.46276E+12 00:00.1 30900473
b8bbef76f8dfee2fe190a283cd5a19a7 start 1.46276E+12 00:00.1 18121481
e8ebfc3f39512eda3aa0702b13ffed63 start 1.46276E+12 00:00.1 18121481
988e4873861347113519fbee6dd1c3b0 start 1.46276E+12 00:00.2 55107008
583361d66ad8b0827cd08d3a5d64af89 stop 1.46276E+12 00:00.2 55107008
users、b、time、product是列。你知道吗
我必须为每个产品的每个用户确定会话。会话定义为difference between the timestamp of stop and start
。
请记住:
there can be many users buying the same product,
each customer have more than one product bought
这里时间戳包括数据和时间,例如(5/9/2016 2:00:00 AM)
您可以使用^{} 。sample的输出有很多
NaN
(因为缺少start
或stop
值),但我认为它可以很好地处理实际数据:编辑:
必须首先将列} 的^{} ,然后将} 进行聚合:
timstamp
转换为带有参数^{aggfunc='first'
添加到pivot_table
,以便按^{编辑1:
我使用
datetime
的新格式创建新示例:相关问题 更多 >
编程相关推荐