基于另一列计算值的出现次数

2024-09-26 21:48:01 发布

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

我有一个关于根据其他列的总和创建pandas数据帧的问题。

例如,我有这个数据框

 Country    |    Accident
 England           Car
 England           Car
 England           Car
  USA              Car
  USA              Bike
  USA              Plane
 Germany           Car
 Thailand          Plane

我想再做一个基于国家所有事故总和的数据框。我们将不考虑事故的类型,而根据国家来总结。

我想要的数据帧是这样的

  Country    |    Sum of Accidents
  England              3
    USA                3
  Germany              1
  Thailand             1

Tags: 数据类型pandas国家carcountry总和usa

热门问题