如果我在一个对象上运行 .count():
animals = all_vals[['Dog','Cat','Mouse','Snake']].count()
并接收此输出:
animals
Out[49]:
Dog 173
Cat 13
Mouse 42
Snake 359
dtype: int64
然后我如何获得每种动物的出现百分比?我可以将 .count 的输出发送到另一个方法吗?
最佳答案
您可以使用:
print (animals)
Dog 173
Cat 13
Mouse 42
Snake 359
Name: animals, dtype: int64
print (100 * animals / animals.sum())
Dog 29.471891
Cat 2.214651
Mouse 7.155026
Snake 61.158433
Name: animals, dtype: float64
关于python - 将 count 方法的输出转换为百分比值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38140910/