python - 寻找前 10 个国家
问题描述
有人可以帮我解决这个问题。我正在尝试从数据框(从 Json 加载)中找到项目最多的前 10 个国家/地区。
我使用了这个查询:json_df.groupby('countrycode').max()
但这导致多行不知道为什么。这些是我的专栏:
Index(['_id', 'approvalfy', 'board_approval_month', 'boardapprovaldate',
'borrower', 'closingdate', 'country_namecode', 'countrycode',
'countryname', 'countryshortname', 'docty', 'envassesmentcategorycode',
'grantamt', 'ibrdcommamt', 'id', 'idacommamt', 'impagency',
'lendinginstr', 'lendinginstrtype', 'lendprojectcost',
'majorsector_percent', 'mjsector_namecode', 'mjtheme',
'mjtheme_namecode', 'mjthemecode', 'prodline', 'prodlinetext',
'productlinetype', 'project_abstract', 'project_name', 'projectdocs',
'projectfinancialtype', 'projectstatusdisplay', 'regionname', 'sector',
'sector1', 'sector2', 'sector3', 'sector4', 'sector_namecode',
'sectorcode', 'source', 'status', 'supplementprojectflg', 'theme1',
'theme_namecode', 'themecode', 'totalamt', 'totalcommamt', 'url'])
解决方案
试试这个:
json_df = json_df[['countrycode','_id']].groupby(['countrycode']).agg(['count'])
它给出的输出显示有多少项目与每个国家代码相关。
推荐阅读
- javascript - 如何在Vue中对对象数组进行排序和过滤
- vba - 无法点击网页中的按钮
- css - 在新的 Unity WebGL 模板中添加全屏显示方式
- java - Spring Boot 应用程序无法通过 TLSv1.2 连接到 RabbitMQ 服务器
- c# - CsvHelper“TypeConverterException:单个字段不支持转换 IEnumerable 类型。”
- java - 将 BSON MongoDB 文档映射到 MyClass.class 对象?
- python - 每前 n 行重复 m 次
- sql-server - SSIS 无法运行创建 excel 文件或另存为复制 excel 文件作为 VBScript 罚款,(没有错误,但执行后没有任何变化)
- for-loop - FOR循环错误“找不到文件”并在Win10 CMD中过早关闭BAT文件
- python - 雪花 PyCharm 连接