使用Pandas对特定列中的某些唯一值执行操作,如中值、平均值等

2024-06-23 19:13:43 发布

您现在位置:Python中文网/ 问答频道 /正文

animals = pd.DataFrame({'animal': ['Dog','Cat','Snake','Snake','Dog','Hamster','Cat','Alligator','Cat','Cat','Dog','Hamster','Alligator'],
                 'age':[2,1,5,7,5,1,4,15,6,9,3,2,40],
                  'weight':[10,4,3,20,15,0.1,6,300,7.1,10,12,0.15,350],
                 'length':[1,0.45,1,2,1.2,0.16,0.40,4.8,0.45,0.50,0.49,0.14,5]})

假设我有这样一个数据框 我想知道猫的平均体重是多少。 如何做到这一点


Tags: 数据dataframeagelengthcatpdweightanimals

热门问题