def test_wdi_search(self): # Test that a name column exists, and that some results were returned # ...without being too strict about what the actual contents of the # results actually are. The fact that there are some, is good enough. result = search('gdp.*capita.*constant') self.assertTrue(result.name.str.contains('GDP').any())
async def gdp(ctx, *, message): matches = wb.search('gdp.*capita.*const') dat = wb.download(indicator='NY.GDP.MKTP.CD', country=[message], start=1999, end=2030) gdp = dat / 1000000000000 await ctx.send(f'**{message} GDP** in USD trillions```{gdp}```')
def chart2(indicator1, countryCode, startY, endY): import matplotlib from io import BytesIO import base64 import pandas as pd pd.core.common.is_list_like = pd.api.types.is_list_like from pandas_datareader import wb matplotlib.use("agg") import matplotlib.pyplot as plt # mathces = wb.search('gdp.*capita.*const') # import wbdata mathces = wb.search('gni.*capita.*const') # set up the countries I want # countries = ['US', 'CA', 'MX'] # set up the indicator I want (just build up the dict if you want more than one) # indicators = {'NY.GNP.PCAP.CD':'GNI per Capita'} # grab indicators above for countires above and load into data frame id = indicator1 ct = countryCode st = startY ed = endY df = wb.download(indicator=id, country=ct, start=st, end=ed) # df is "pivoted", pandas' unstack fucntion helps reshape it into something plottable dfu = df.unstack(level=0) # a simple matplotlib plot with legend, labels and a title dfu.plot() plt.legend(loc='best') plt.title("Result") plt.xlabel('Date') plt.ylabel('Indicator1') sio = BytesIO() plt.savefig(sio, format='png') data = base64.encodebytes(sio.getvalue()).decode() print(data) html = ''' <html> <body> <img src="data:image/png;base64,{}" /> </body> <html> ''' picture = "data:image/png;base64," + data # print(picture) plt.close() # return html.format(data) return render_template("home.html", picture=picture)
def test_wdi_search(self): # Test that a name column exists, and that some results were returned # ...without being too strict about what the actual contents of the # results actually are. The fact that there are some, is good enough. result = search('gdp.*capita.*constant') self.assertTrue(result.name.str.contains('GDP').any()) # check cache returns the results within 0.5 sec current_time = time.time() result = search('gdp.*capita.*constant') self.assertTrue(result.name.str.contains('GDP').any()) self.assertTrue(time.time() - current_time < 0.5) result2 = WorldBankReader().search('gdp.*capita.*constant') session = requests.Session() result3 = search('gdp.*capita.*constant', session=session) result4 = WorldBankReader(session=session).search('gdp.*capita.*constant') for result in [result2, result3, result4]: self.assertTrue(result.name.str.contains('GDP').any())
def get_data_id(self, search_keywords): """ :param search_keywords: list :return: list """ search_keywords = search_keywords.split() try: data = wb.search('|'.join(search_keywords)) self.data = data return data['name'].to_list() except Exception as error: self.current_error = error self.data = pd.DataFrame() return pd.DataFrame()
from pandas_datareader import wb import matplotlib.pyplot as plt mathces = wb.search('gni.*capita.*const') #grab indicator,country, period I want and load into data frame df = wb.download(indicator='NY.GNP.PCAP.CD', country=['CL', 'UY', 'HU'], start=1990, end=2010) #df is "pivoted", pandas' unstack fucntion helps reshape it into something plottable dfu = df.unstack(level=0) # a simple matplotlib plot with legend, labels and a title dfu.plot(); plt.legend(loc='best'); plt.title("GNI Per Capita ($USD, Atlas Method)"); plt.xlabel('Date'); plt.ylabel('GNI Per Capita ($USD, Atlas Method'); plt.show();
def bpress(): global feat global pos text=e.get() feat=feat.append(wb.search(text,field='name',case=False))
""" Author: Самаркин Date: 27/10/2019 Purpose: test """ # стандартная секция импорта, будет использоваться всегда # модули числовых расчетов import scipy as sc import numpy as np import pandas as pd # модуль библиотеки для вывода графиков в стиле Matlab import matplotlib matplotlib.use( 'Qt5Agg' ) # библиотека для вывода графиков на базе Qt5, нужен импорт модуля PyQt5 # модуль печати плоских графиков import matplotlib.pyplot as plt plt.style.use('bmh') # можно попробовать также 'ggplot' или 'classic' fig = plt.figure( ) # поверхность для вывода графиков (в виде всплывающего окна) from pandas_datareader import wb matches = wb.search('gdp.*capita.*const') dat = wb.download(indicator='NY.GDP.PCAP.KD', start=2005, end=2008) print(dat) plt.show()
def search_wb(query): return wb.search(query)[["id","name","source"]]
def search_wb(query): return wb.search(query)[["id", "name", "source"]]
print(inflation.info()) # Fama/French from pandas_datareader.famafrench import get_available_datasets print(get_available_datasets()) ds = web.DataReader('5_Industry_Portfolios', 'famafrench') print(ds['DESCR']) # World Bank from pandas_datareader import wb gdp_variables = wb.search('gdp.*capita.*const') gdp_variables.head() wb_data = wb.download(indicator='NY.GDP.PCAP.KD', country=['US', 'CA', 'MX'], start=1990, end=2019) print(wb_data.head()) # OECD df = web.DataReader('TUD', 'oecd', end='2015') print(df[['Japan', 'United States']]) # EuroStat
import pandas as pd import requests # Specific imports import pandas_datareader as pdr from pandas_datareader import wb # In[28]: # This link proved very useful : # https://pydata.github.io/pandas-datareader/stable/remote_data.html#world-bank # In[71]: # Search in the available indicators which on matches our search matches = wb.search('Statistical') matches[['id', 'name', 'sourceNote']].values # Seems like the 2nd indicator is the one we are interested in # In[73]: MY_IND = 'IQ.SCI.OVRL' START_YEAR = 2010 matches = wb.download(indicator=MY_IND, country='all', start=START_YEAR, end=2019) # In[74]:
symbol = 'AAPL' starttime = datetime.datetime(2015, 1, 1) endtime = datetime.datetime(2018, 12, 31) apple = pdr.get_data_yahoo(symbol, starttime, endtime) type(apple) # <class 'pandas.core.frame.DataFrame'> apple.to_csv('apple.csv') symbol2 = '^GSPC' starttime2 = datetime.datetime(2010, 1, 1) endtime2 = datetime.datetime(2019, 1, 7) sp500 = pdr.get_data_yahoo(symbol2, starttime2, endtime2) sp500.to_csv('sp500.csv') # for world bank dataset matches = wb.search('gdp.*capita.*const') data = wb.download(indicator='NY.GDP.PCAP.KD', country=['US', 'CA', 'MX'], start=2005, end=2008) data.head() data['NY.GDP.PCAP.KD'].groupby(level=0).mean() wb.search('cell.*%').iloc[:, :2] ind = ['NY.GDP.PCAP.KD', 'IT.MOB.COV.ZS'] ind = ['NY.GDP.PCAP.KD', 'IT.MOB.COV.ZS'] Idat = wb.download(indicator=ind, country='all', start=2011, end=2011).dropna() Idat.columns = ['gdp', 'cellphone'] print(Idat.head()) print(Idat.tail())
""" INTL 550 - HW2 (Data collection) Name : Shukhrat Khuseynov ID : 0070495 """ import numpy as np import pandas as pd from pandas_datareader import wb # World Bank API from pandas_datareader matches1 = wb.search('life expectancy') # choosing SP.DYN.LE00.IN matches2 = wb.search('gdp per capita') # choosing NY.GDP.PCAP.CD matches3 = wb.search('school enrollment') # choosing SE.PRE.ENRR matches4 = wb.search('birth rate') # choosing SP.DYN.CBRT.IN # obtaining all indicators at once df = wb.download(indicator=[ 'SP.DYN.LE00.IN', 'NY.GDP.PCAP.CD', 'SE.PRE.ENRR', 'SP.DYN.CBRT.IN' ], country='TJ', start=1990, end=2020) # formatting the table df.columns = ['lifexp', 'gdp', 'school', 'birth'] df = df[::-1] # reverting the data df = df.dropna() print(df)
import pandas_datareader.wb as wb data = wb.search(string='SE.PRM.TENR', field='id') data
def world_bank(): from pandas_datareader import wb gdp_variables = wb.search('gdp.*capita.*const') gdp_variables.head()
""" Created on Fri Nov 10 19:11:36 2017 @author: mmic """ import pandas as pd import numpy as np import datetime import matplotlib.pyplot as plt import pandas_datareader.data as web from pandas_datareader import wb ## Searching variables with the key word CO2 dat=wb.search('CO2').iloc[:,:2] print(dat) # Importing Data from World Bank API var = ['EN.ATM.GHGT.KT.CE','EN.CO2.TRAN.ZS','EN.CO2.BLDG.ZS', 'EN.CO2.MANF.ZS','EN.CO2.OTHX.ZS','EN.CO2.ETOT.ZS'] con = ['WLD','USA','CHN','IND','JPN','RUS'] st=1960 en=2016 df= wb.download(indicator=var, country=con, start=st, end=en).dropna() # Renaming the variable names df=df.rename(columns={'EN.ATM.GHGT.KT.CE':'TE'}) # Graph 1 df1=df.unstack(level=0)
# Japan 2014 127276000 # 2013 127445000 # 2012 127629000 # 2011 127833000 # 2010 128070000 # ... ... # United States 1989 246819000 # 1988 244499000 # 1987 242289000 # ... ... # 1962 186538000 # 1961 183691000 # 1960 180671000 # [110 rows x 1 columns] print(wb.search('gdp.*capita.*const').iloc[:, :2]) # id name # 685 6.0.GDPpc_constant GDP per capita, PPP (constant 2011 internation... # 8086 NY.GDP.PCAP.KD GDP per capita (constant 2010 US$) # 8088 NY.GDP.PCAP.KN GDP per capita (constant LCU) # 8090 NY.GDP.PCAP.PP.KD GDP per capita, PPP (constant 2011 internation... # 8091 NY.GDP.PCAP.PP.KD.87 GDP per capita, PPP (constant 1987 internation... f = wb.download(indicator='SP.POP.TOTL', country=['JP', 'US'], start=1960, end=2014) f2 = f.unstack(level=0) print(f2) # SP.POP.TOTL # country Japan United States