IMF的官方网站可以查到世界大部分国家的经济数据,比如增长率,GDP,人均GDP,人口等等。
我用tkinter实现了从IMF获取数据,并实现页面展示,非常便利。这大概是经济爱好者的强迫症吧。
首先从这里获取Excel: https://www.imf.org/external/datamapper/datasets/WEO
然后对Excel进行一点加工,如图

然后运行python程序:
#-*- coding:utf-8 -*-
import requests,time,datetime
import tkinter as tk #使用Tkinter前需要先导入
from tkinter import filedialog,messagebox,ttk
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sqlalchemy import create_engine
plt.rcParams['font.sans-serif']=['SimHei']
conn=create_engine("mysql+pymysql://root:dio350922@127.0.0.1:3306/economy")
window = tk.Tk()
dfc=pd.read_sql("select country,country_cn 国家 from countrylist where iscountry='Y' order by pinyin",conn) #国家中英文列表
countrymap=dict(zip(dfc['country'],dfc['国家'])) #国家英中文对照
countrylist=dfc['国家'].tolist() #国家列表
indexmap={
'增长率':'growth','GDP':'gdp','人均GDP':'rjgdp','GDP(PPP)':'ppp','人均GDP(PPP)':'rjppp','人口':'renkou'}
indexlist=list(indexmap)
typemap={
'线形图':'line','柱状图':'bar'}
window.title('经济指标曲线图')
w_width=1100
w_height=750
scn_width=window.maxsize()[0]
x_point=(scn_width-w_width)//2
window.geometry('%dx%d+%d+%d' %(w_width,w_height,x_point,100))
window.wm_attributes('-topmost',True)
window.tk_focusFollowsMouse()
window.bind("<Escape>",lambda event:window.iconify())
#更新数据
def getfile(type):
file=filedialog.askopenfilename(filetype=[('Excel','.xls'),('Excel','.xlsx')])
df=pd.read_excel(file)
index=df

通过Python及Tkinter从IMF官网获取并展示各国经济增长率、GDP等数据,支持线形图与柱状图展示。
最低0.47元/天 解锁文章
766

被折叠的 条评论
为什么被折叠?



