2024-04-20 01:29:59 发布
网友
我有这个数据框:
Col1 | Col2 | Col3 \n A | 1 | 1 \n B | 23 | 2 \n C | 21 | 1 \n
在Pandas中,将A&B相加、合并或求和是否可行,以便如下所示:
Col1 | Col2 | Col3 \n A | 24 | 3 \n C | 21 | 1 \n
我试过分组,但它不会工作,因为有不同的键A和B涉及?你知道吗
对相同的类别使用^{},然后groupby+sum:
groupby
sum
df = df.groupby(df['Col1'].replace({'B':'A'})).sum().reset_index() print (df) Col1 Col2 Col3 0 A 24 3 1 C 21 1
对相同的类别使用^{} ,然后
groupby
+sum
:相关问题 更多 >
编程相关推荐