问题
Very simple question here which i could not find the answer for reading the docs (below is an excerpt):
import pandas_datareader.data as web # pandas 0.19.x and later
import datetime
start = datetime.datetime(2010, 1, 1)
end = datetime.datetime(2013, 1, 27)
gdp = web.DataReader("GDP", "fred", start, end)
Documentation: http://pandas-datareader.readthedocs.io/en/latest/remote_data.html
Note that if you have an older version of pandas you should instead do the following import:
import pandas.io.data as web # pandas 0.18.x and earlier
So my question is ... where can one find a list of the acceptable parameters (like GDP), and what they correspond to? Even GDP has many different flavors - and FRED lists BEA Account Code's to clarify so I'm not sure how these are reconciled.
回答1:
These are ticker symbols, basically stocks. You can find several lists online e.g. eodata, though I'm not sure where or if there is a definitive list for FRED (or the other data sources)...
GDP is Goodrich Petroleum Corporation.
回答2:
Nobody posted a relevant answer so through trial and error I figured this out
There doesn't appear to be a repository or search function as far as I can tell in the library, but the relevant tickers are displayed at the top of each indicator when you search for them in FRED. For example, if you search "Real Gross Domestic Product", once you get that chart pulled up in FRED, the first paragraph shows a ticker "GDPC1" which is what you need.
Also, you can pass a list of tickers in like so to get multiple series added to your dataframe:
In [32]: gdp=web.DataReader(ticker_list, "fred", start, end)
回答3:
The FRED API includes full text search, and the wrappers fredapi and fred leverage this functionality to return data series identifiers against your query.
You just need to sign up for an API key.
回答4:
Like @Solaxun I couldn't find a good way to search for the relevant codes other than going to FRED. For example, I clicked around to get the percentage change in GDP here:
https://fred.stlouisfed.org/series/A191RL1Q225SBEA
And you can take that code at the end of the URL A191RL1Q225SBEA
and plug it in to get the series like this:
gdp_pct_change = web.DataReader("A191RL1Q225SBEA", "fred", start, end)
Here are some other codes for convenience and to give you a sense the breadth of data you can get there. Note that for many series like GDP there are many variants (seasonally vs not seasonally adjusted, real vs nominal, etc.) so there often is no substitute for just going directly to FRED and reading the exact descriptions.
- Real Gross Domestic Product (A191RL1Q225SBEA) -- percent change
- Real Gross Domestic Product (GDPC1) -- dollars
- Federal Debt: Total Public Debt as Percent of Gross Domestic Product (GFDEGDQ188S)
- Consumer Price Index for All Urban Consumers: All Items (CPIAUCSL)
Employment related stats:
- Civilian Unemployment Rate (UNRATE)
- All Employees: Total Nonfarm Payrolls (PAYEMS)
- 4-Week Moving Average of Initial Claims (IC4WSA)
Interest Rates:
- 10-Year Treasury Constant Maturity Rate (DGS10)
- Effective Federal Funds Rate (FEDFUNDS)
- 3-Month London Interbank Offered Rate (LIBOR), based on U.S. Dollar (USD3MTD156N)
Stock Indices:
- S&P 500 (SP500)
- Nikkei Stock Average, Nikkei 225 (NIKKEI225)
回答5:
Sorry to bring back an old topic, but I figured out a way to find the economic codes for the pandas_datareader using FRED data. To do this: 1. install the package 'fredapi' using conda install or pip install at [https://anaconda.org/conda-forge/fredapi] 2. Sign up for a FRED API key on the FRED website 3. Use the function:
from fredapi import Fred as fred
fred = fred(api_key='your_api_key')
fred.search('natural gas exports').T
It will output a variety of codes and descriptions depending on what you are looking for.
来源:https://stackoverflow.com/questions/28445106/pandas-importing-fred-data-pandas-io-data-or-pandas-datareader