Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve multiple indicators at once #12

Open
GitHunter0 opened this issue Apr 29, 2020 · 2 comments
Open

Retrieve multiple indicators at once #12

GitHunter0 opened this issue Apr 29, 2020 · 2 comments

Comments

@GitHunter0
Copy link

Is it possible to retrieve multiple (or all) indicators at once? I believe it is a very important feature but I could not find a way to do that.

Thank you very much in advance, this module is awesome.

@mwouts
Copy link
Owner

mwouts commented Apr 29, 2020

Hello @fmgithub2017 , sorry we don't have this. We could think of implementing it, however I am not sure that all the indicators will have the same dimensions, so it's not clear whether it would make sense to gather all the indicators in a single data frame.

Anyway you can try it yourself! I've just tested this:

import pandas as pd
from tqdm import tqdm
from world_bank_data import get_indicators, get_series, get_topics

# Climate Change = topic 19
get_topics()

climate_change_indicators = get_indicators(topic=19)
climate_change_indicators

# May work on another example?
# Here it fails with the message that SH.H2O.SAFE.RU.ZS may have been deleted or archived.
all_values = pd.DataFrame({serie_id: get_series(serie_id, simplify_index=True)
                           for serie_id in tqdm(climate_change_indicators.index)})

but, as you see in the comment, this fails on a missing indicator.

Maybe you could then define a function for that that would also intercept the errors, etc... Let me know how it goes.

@GitHunter0
Copy link
Author

GitHunter0 commented Apr 30, 2020

Hey @mwouts , I appreciate very much the reply.

The issue of dimensions you posed might be a real problem indeed. However, many databases have all the variables with the same dimension, which is the case of World Development Indicators and Doing Business, for instance. I guess the ones that do not, you could just leave an error and warning messages.

Here is an example with 'pandas_datareader' module, in which the user can retrieve multiple or all indicators of a database:
from pandas_datareader import wb
Select Doing Business Indicators
dfa = wb.get_indicators().reset_index()
dfa = dfa.loc[dfa.source=='Doing Business',]
indicators_id = dfa.id
print(indicators_id)
Retrieve all indicators of the Doing Business database
df = wb.download(indicator=indicators_id, country='all', start=2016, end=2017).reset_index()
df

However, I would prefer to use your module 'world_bank_data' because it is faster, isn't it?

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants