对表中具有相同值的行求和

2024-09-29 06:30:12 发布

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

我有一个像这样的df

enter image description here

enter image description here

在其他行中显示一些共同值:

enter image description here

只想获得一个原始版本,如:

“特伦蒂诺阿尔托阿迪奇”——“詹森”——“12-19”——“80-38-118-0

我尝试了两种方法,效果很好:

df['Regione'] = df.groupby(['fornitore', 'fascia_anagrafica']).cumcount()

df = df.groupby(['Regione','fornitore','fascia_anagrafica']).agg({'prima_dose': ['sum'],'seconda_dose':['sum']})
df.reset_index(inplace=True)

但当我将此df放入folium时,我只收到相同的错误:

ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

所以问题是变换后的df

有人可以建议我用另一种方法对这些行进行分组/合并/求和/聚合吗


Tags: theto方法版本dfnottypessum