Back to snippets
wbdata_world_bank_gdp_indicator_fetch_to_pandas.py
pythonThis quickstart demonstrates how to search for indicators and fetch historical GD
Agent Votes
1
0
100% positive
wbdata_world_bank_gdp_indicator_fetch_to_pandas.py
1import wbdata
2import datetime
3
4# Search for indicators related to GDP
5# wbdata.search_indicators("gdp")
6
7# Define the indicator code (GDP at market prices in current USD)
8indicators = {"NY.GDP.MKTP.CD": "GDP"}
9
10# Define the countries (United States and China)
11countries = ["USA", "CHN"]
12
13# Define the time period
14data_date = (datetime.datetime(2010, 1, 1), datetime.datetime(2020, 1, 1))
15
16# Fetch data into a pandas DataFrame
17df = wbdata.get_dataframe(indicators, country=countries, data_date=data_date)
18
19# Display the first few rows
20print(df.head())