pandas-datareader
pandas-datareader copied to clipboard
FRED - How to query units, frequency..?
I'm using pandas-datareader package to query data from the FRED's database and would like to know whether there is an opportunity to set the units and frequency while querying the data !?
For example:
- querying the CPI (CPIAUCSL) but with "percentage change from year ago" as unit or "yearly" frequency!?
Yes!! you can do that something like that I think ft=web.DataReader("your time series", start=datetime(2017, 2, 9), end=datetime(2017, 5, 24))
here ft is some random variable
:
did you ever figure out how to do this? I can figure out how to set units either
was looking for this too as fred's api does support a unit parameter. I was using that, but i find PDR to be faster than freds library. after looking at the source code for a little bit, i realize you can hack the request for units in....Im almost ashamed to provide this hack - but it does work. so what you can do is append the units to the requested series code you pass in to the fred constructor like this.
code = 'PAYEMS'
pdr.DataReader(code + '&fgst=pc1', source, start = st_dt, end = None)
That will return year over year percent change instead of the default lin units. u can do the same for other parameters: For frequency, the url parameter is 'fq', and for frequency aggregation, it is 'fam'.
interestingly i do see params as a supported property of the basereader. but it seems the DataReader constructor requires params and the request is executed immediately. so doesnt give u a chance to set that params property