寻找前10个国家

2024-09-28 03:14:34 发布

您现在位置:Python中文网/ 问答频道 /正文

有人能帮我吗。我试图从一个数据框架(从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'])

Tags: 数据项目project框架idjsondf国家
1条回答
网友
1楼 · 发布于 2024-09-28 03:14:34

试试这个:

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

它给出的输出显示了有多少个项目与每个countrycode相关

相关问题 更多 >

    热门问题