pandas-datareader icon indicating copy to clipboard operation
pandas-datareader copied to clipboard

FRED - How to query units, frequency..?

Open PizzaMargherita21 opened this issue 4 years ago • 3 comments

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!?

PizzaMargherita21 avatar May 19 '21 06:05 PizzaMargherita21

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

:

Tanu1201 avatar Aug 30 '21 15:08 Tanu1201

did you ever figure out how to do this? I can figure out how to set units either

evansanchez15 avatar Jun 23 '22 18:06 evansanchez15

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

dss010101 avatar Oct 13 '22 00:10 dss010101