python - python计数来自csv pandas的行
问题描述
colors.csv
id name rgb is_trans
0 -1 Unknown 0033B2 f
1 0 Black 05131D f
2 1 Blue 0055BF t
你如何计算有多少 f & t,(如下所示)
colors_summary = colors.count('is_trans')
print(colors_summary)
寻找结果
is_trans id name rgb
f 107 107 107
t 28 28 28
解决方案
假设你有
color_df # dataframe object
你可以这样做:
result_df = color_df.groupby('is_trans').count()
print(result_df) # should give you what you ask for.
推荐阅读
- php - Laravel FormRequest 验证动态行
- php - 使用 php 文件系统过滤数据库
- testing - NestJS Bull Queues:如何跳过测试环境中的处理?
- java - 启动配置 all_client 引用不存在的项目库
- tomcat - 在 Apache Solr 4.4 中更改 synonyms.txt 文件后是否需要重新启动所有 tomcat solr 节点
- mongodb - SortByCount 并显示每个文档
- bash - 如何正确地将 Bash 数组分配给另一个变量?
- jquery - 选择带有“是”字样的列表选项时尝试显示 Div - Woocommerce
- events - Acumatica - 调用删除事件时更新其他订单的最佳解决方案是什么?
- postgresql - Postgres 对特定数据进行匿名/随机化所有具有数据域的数据