首页 > 解决方案 > 寻找前 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'])

标签: pythonjsondataframe

解决方案


试试这个:

json_df = json_df[['countrycode','_id']].groupby(['countrycode']).agg(['count'])

它给出的输出显示有多少项目与每个国家代码相关。


推荐阅读