Pandas Dataframe-按Col A分组,并对每个分组Col C求和

时间:2019-04-11 04:12:01

标签: python pandas m

我有以下数据框:

COLA    COLB    COLC
a       cfg     100
b       gdd     100     
c       ert     100
d       yrt     100
a       yui     100
d       ouo     100
a       ooo     100
b       qwe     100

我想合并COLA中的所有项目(groupby?),然后在COLC中将它们的值求和,最后得到

COLA    COLC
a       300
b       200    
c       100
d       200

我正在尝试:

df.groupby('COLA').sum('COLC')

1 个答案:

答案 0 :(得分:2)

GroupBy对象以与DataFrame相同的方式支持列索引,并返回修改后的GroupBy对象

@ContextConfiguration(
initializers = ConfigFileApplicationContextInitializer.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
class BaseSpec extends Specification {
@Shared
WireMockServer wireMockServer

def setupSpec() {

wireMockServer = new WireMockServer(options().port(PORT).jettyHeaderBufferSize(12345)
.notifier(new ConsoleNotifier(new Boolean(System.getenv(“IT_WIREMOCK_LOG”) ?: ‘false’))) 
.extensions(new ResponseTemplateTransformer(true)))

wireMockServer.start()

}