pandas 从字符串列表中添加逗号分隔计数

8dtrkrch  于 2023-06-04  发布在  其他
关注(0)|答案(1)|浏览(201)

我在df中有一个名为diff_2的列,它的格式如下:

diff_2
Backward compatibility errors (16):
error at /Users, in API GET /studies/{studyId} the response property 'id' became optional for the status '200' [response-property-became-optional]. 

error at /Users, in API GET /projects/{projectId} the response property 'id' became optional for the status '200' [response-property-became-optional]. 

error at original_source=/Users continuous/tickets api path removed without deprecation [api-path-removed-without-deprecation]. 

error at original_source=/Users, in API GET /projects/filters api path removed without deprecation [api-path-removed-without-deprecation]. 

error at original_source=/Users, in API GET /expressions/bytes api path removed without deprecation [api-path-removed-without-deprecation]. 

error at original_source=/Users, in API GET /continuous/filters api path removed without deprecation [api-path-removed-without-deprecation]. 

error at original_source=/Users, in API GET /expressions/tickets api path removed without deprecation [api-path-removed-without-deprecation]. 

error at original_source=/Users, in API GET /continuous/{continuousId}/tickets api path removed without deprecation [api-path-removed-without-deprecation]. 

error at original_source=/Users, in API GET /continuous/{continuousId}/bytes api path removed without deprecation [api-path-removed-without-deprecation]. 

error at original_source=/Users, in API GET /expressions/{expressionId}/bytes api path removed without deprecation [api-path-removed-without-deprecation]. 

error at original_source=/Users, in API GET /studies/filters api path removed without deprecation [api-path-removed-without-deprecation]. 

error at original_source=/Users, in API GET /expressions/{expressionId}/tickets api path removed without deprecation [api-path-removed-without-deprecation]. 

error at original_source=/Users, in API GET /studies api path removed without deprecation [api-path-removed-without-deprecation]. 

error at original_source=/Users, in API GET /projects api path removed without deprecation [api-path-removed-without-deprecation]. 

error at original_source=/Users, in API GET /expressions/filters api path removed without deprecation [api-path-removed-without-deprecation]. 

error at original_source=/Users, in API GET /continuous/bytes api path removed without deprecation [api-path-removed-without-deprecation].

通过它我提取了content列,也就是方括号中的文字。还有count,它显示在列的第一行中的错误旁边。

content                                                                    count
Response Property Became Optional,API Path Removed Without Deprecation      16

但我想实现的是bot类型的更改计数,逗号分隔,所以不是计数为16,我希望它是这样的:

content                                                                    count
Response Property Became Optional,API Path Removed Without Deprecation,     2,14

我不知道该怎么做,任何建议或想法都会很有帮助。

cngwdvgl

cngwdvgl1#

提取content列(作为DataFrame)后,用途:

cnt = df.groupby('content').count()

这应该给予结果:
| 指数|计数|
| - -----|- -----|
| 响应属性变为可选|2|
| API路径已删除但未弃用|十四|
注意:我是用手机回答的,所以我不能测试我的答案,请查看pandas用户指南中的“groupby aggregate”,以获得一些很好的例子。

相关问题