为一个数据框中的行-列组合生成一个列表,第二个数据框中的数据包含更多的列值组合

问题描述

我需要为每个国家生成不同年份的人口清单。我需要的信息包含在两个数据框中

  1. 第一个数据框gni_per_capita包含国家/地区名称和 年份。此数据框中的国家/地区的年份范围不同

  2. 第二个数据框hihd也包含国家/地区名称和日期, 但县的范围更广,范围更广 每个国家/地区的日期范围。 第二个数据框包含每年每个国家的人口,第二个则不。

我需要在第一个数据框中生成每个国家/地区每年的人口清单。

给了我以下提示:

1. first,get a unique list of countries from gni_per_capita. 
2. Loop through the list,and get the available years for that country. 
3. Then .loc index hihd to get the population rows where both the country
    and years are correct (hihd.Year.isin(?)). 
4. Append these to the list
    one by one.

到目前为止,我已经从第一个数据帧创建了一个包含国家和年份的系列

group = gni_per_capita.groupby('Entity')

ync = group.apply(lambda x: x['Year'].unique())

但是,我正在努力将第二个数据框与创建的系列相结合

mask = hihd.Year.isin(ync)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)