我有一个像这样的数据集
users b c d product
8fa683e59c02c04cb781ac689686db07 ggstart 1.46276E+12 00:00.0 55107008
335644267c1d5f04eaea7bc6f51b1861 ggstart 1.46276E+12 00:00.0 55107008
ca3071aad676bc963795a2b09635cdf0 ggstop 1.46277E+12 00:00.0 55107008
17412dec7d3d02c9b0b1c3d1c3571c5c ggstop 1.46276E+12 00:00.0 10655437
f81167c854f1a0c86cab6188f9995824 ggstart 1.46276E+12 00:00.1 55107008
17412dec7d3d02c9b0b1c3d1c3571c5c ggstart 1.46276E+12 00:00.1 10655437
a2659df45c8d05f326225fa5b1063ac9 ggstart 1.46276E+12 00:00.1 30900473
b8bbef76f8dfee2fe190a283cd5a19a7 ggstart 1.46276E+12 00:00.1 18121481
e8ebfc3f39512eda3aa0702b13ffed63 ggstart 1.46276E+12 00:00.1 18121481
988e4873861347113519fbee6dd1c3b0 ggstart 1.46276E+12 00:00.2 55107008
583361d66ad8b0827cd08d3a5d64af89 ggstop 1.46276E+12 00:00.2 55107008
用户,b,c,产品是列。
我必须确定每个产品是由多少独特用户购买的。有成千上万的这样的线。 请记住:
there can be many users buying the same product,
each customer have more than one product bought
首先,我尝试制作独特用户矩阵和独特的PRODUCT。但我只有16个产品,用户就像5000个。 有什么方法可以找到
答案 0 :(得分:0)
In [51]: df.groupby(['product'])['users'].nunique()
Out[51]:
product
10655437 1
18121481 2
30900473 1
55107008 6
Name: users, dtype: int64