countries = ['USA', 'SWE', 'CHE'] indicators = {'NY.GDP.PCAP.KD': 'GDP per capita'}

start_date = '2000' end_date = '2019'

data = pd.DataFrame()

for country in countries: temp_data = worldbank.download(indicator=indicators, country=country, start=start_date, end=end_date) temp_data = temp_data.reset_index().pivot(index='year', columns='country', values='GDP per capita') data = pd.concat([data, temp_data], axis=1)

data.plot() plt.title('GDP per capita of USA, SWE and CHE') plt.xlabel('Year') plt.ylabel('GDP per capita') plt.show()

#使用pandas_datareader获取世界银行数据库中美国USA、瑞典SWE、瑞士CHE三个国家近20年的NYGDPPCAPKD数据并作图对比import pandas as pdimport matplotlibpyplot as pltimport pandas_datareaderwb as worldbank

原文地址: https://www.cveoy.top/t/topic/bd2K 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录