【发布时间】:2021-02-03 13:45:28
【问题描述】:
每次我重新启动我的 jupyter-lab 笔记本时,value_count() 都会显示不同的值。
bid = customers['BasketID']
bid.value_counts()
这是两次执行的结果:
576339 542
573585 535
579196 533
580727 529
578270 442
...
563453 1
C567706 1
548001 1
C546895 1
574519 1
Name: BasketID, Length: 24627, dtype: int64
576339 542
573585 535
579196 533
580727 529
578270 442
...
C562808 1
575205 1
549004 1
C542991 1
565577 1
Name: BasketID, Length: 24627, dtype: int64
如您所见,字母开头总是有不同的数字。
由于在笔记本中我必须引用其中一个数字,所以我不能让它在每次迭代时都改变。
有没有办法使方法的输出具有确定性?
我猜这种奇怪的行为是由于该方法使用的排序算法造成的。也许有一种方法可以查看/设置算法使用的随机数生成器的种子?
【问题讨论】:
-
也许所有这样的“C”代码都计数为 1?好像很少啊,能不能到
df[df['BasketId'].str.startswith('C')]查看完整列表。 -
不用担心它存储的顺序,为什么不能通过
.loc获取关联值?bid.value_counts().loc["C567706"] -
@CameronRiddell 因为这不是我需要的。我需要的是表明列中有非数值。
标签: python pandas jupyter-notebook jupyter jupyter-lab