首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >两个variables_difficulty实现的相同大小的散点图

两个variables_difficulty实现的相同大小的散点图
EN

Stack Overflow用户
提问于 2019-08-05 15:45:44
回答 2查看 111关注 0票数 2

数据源: https://www.kaggle.com/worldbank/world-development-indicators 文件夹:‘world-development-’File:Indicators.csv

我试图在两个变量之间绘制散点图。然而,这两个变量的大小并不相同。

数据库如下所示:它是通过名称数据保存的:

代码语言:javascript
复制
CountryCode IndicatorName                   Year    Value
USA         Population, total               1993    72498
USA         Population, total               1994    76700
USA         Population, female (% of total) 1993    50.52691109
USA         Population, female (% of total) 1994    50.57235984
USA         GDP per capita (const 2005 US$) 1994    23086.93795
USA         Population, female (% of total) 1988    50.91933134
USA         Population, total               1988    61077

我想在两件事之间画一张散点图:绝对女性人口和人均GDP (const 2005美元)。绝对女性人口=人口,*总人口,女性(%)

挑战如下:

a)一个国家的总人口、女性人口和国内生产总值存在不同的年份。例如,美国,比方说人口的数值,总数只存在20年,女性人口的数字是18年,国内生产总值的数值只有10年。

没有NAN/Null值

I需要这些值,其中所有这些参数的值在给定年份的国家中都是

我对python很陌生,所以我无法在代码中列出我想要的内容。有谁能帮忙吗?

代码语言:javascript
复制
 femalepop_filter = data['IndicatorName'].str.contains('Population,      
 female')
 FemalePop = data[femalepop_filter]

 Pop_total=data['IndicatorName'].str.contains('Population, total')
 Pop_Tot=data[Pop_total] 

 hist_indicator = 'GDP per capita \(const 2005'
 GDP_Filter = data['IndicatorName'].str.contains(hist_indicator)
 GDPValues=data[GDP_Filter]

 c1 = (FemalePop['CountryCode']) 
 c2 = (GDPValues['CountryCode']) 
 c3 = (Pop_Tot['CountryCode'])
 c4 = np.intersect1d(c1,c2)
 c5 = np.intersect1d(c3,c4)

我捕获了所有参数的国家代码。现在我在c5找到了他们的交叉口。有人能帮助我如何获得国家代码在c5中的数据吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-08-07 08:15:12

我找到了答案。

代码语言:javascript
复制
    data2=data[data['CountryCode'].isin(c5)]
    #Getting all the intersection of country codes in one dataset

    data2['concatyearandCC'] = data2["CountryCode"] + "" + data2["Year"].map(str)
    #Introducing new column which is concatenation of country code and Year so that I 
    #get all the rows corresponding to same year and country code.

    c9 = pd.merge(FemalePop2,Pop_Tot2,on="concatyearandCC")
    c10= pd.merge(c9,GDPValues2,on="concatyearandCC")
    #Merging datasets containing female population%, GDP and total population of  
    #females so that I can calculate absolute number of females.

    c10.rename(columns={'Value_x': 'Population_female%', 'Value_y': 'Population 
    Total', 'Value': 'GDP Per capita'}, inplace=True)
    #Renaming some columns for ease.

    c10_Final['Abs_Female_Pop'] = c10_Final['Population_female%'] 
    *c10_Final['Population Total']
    #Finding absolute female population
票数 1
EN

Stack Overflow用户

发布于 2019-08-05 17:14:05

错误告诉您Python不知道如何连接("&")字符串和布尔变量。

将bool转换为字符串,您的连接应该可以工作。

通常,逐步调试代码。首先看看变量包含了什么。您可以使用Python的“漂亮打印”(pprint)模块。这样您就可以打印出各种变量,以查看它们包含了什么。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57361987

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档