Skip to content

Multiple series for FRED data #3413

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

Closed
jseabold opened this issue Apr 22, 2013 · 4 comments · Fixed by #5492
Closed

Multiple series for FRED data #3413

jseabold opened this issue Apr 22, 2013 · 4 comments · Fixed by #5492
Labels
IO Data IO issues that don't fit into a more specific label
Milestone

Comments

@jseabold
Copy link
Contributor

I haven't looked under the hood yet, but it doesn't look like you can grab multiple series from FRED data at the moment. This works

from pandas.io.data import DataReader

merge = lambda x,y : x.merge(y, left_index=True, right_index=True)
dta = reduce(merge, [DataReader(i, "fred") for i in ["AKUR", "ALUR","GAUR"]])

but this just hangs and then returns an empty DataFrame

dta = DataReader(["AKUR", "ALUR","GAUR"], "fred")
@TomAugspurger
Copy link
Contributor

I was just looking at this over the weekend. Doing something similar to how multiple yahoo symbols are handled I came up with:

def get_data_fred2(name=None, start=dt.datetime(2010, 1, 1),
                   end=dt.datetime.today()):
    """
    Get data for the given name from the St. Louis FED (FRED).
    Date format is datetime

    Returns a DataFrame.
    """
    lst = []
    name = list(name)

     for n in name:
        start, end = _sanitize_dates(start, end)
        if(n is None):
            print "Need to provide a name"
            return None
        fred_URL = "http://research.stlouisfed.org/fred2/series/"
        url = fred_URL + '%s' % n + \
            '/downloaddata/%s' % n + '.csv'
        data = read_csv(urllib.urlopen(url), index_col=0, parse_dates=True,
                        header=None, skiprows=1, names=["DATE", n])
        lst.append(data.truncate(start, end))

    return concat(lst, axis=1, join='outer')

I haven't had any time to clean it up and make it more robust. It has zero exception handling, but as long as all of the series passed are valid it should work.

@jreback
Copy link
Contributor

jreback commented Jun 6, 2013

@y-p is this issue closable by #3469? (which is merged)

@TomAugspurger
Copy link
Contributor

No. I didn't touch multiple series at all. I just added '.' as a NaN.

@jreback
Copy link
Contributor

jreback commented Jun 6, 2013

ahh...ok..thanks...leaving open for 0.12 then (was following links)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO Data IO issues that don't fit into a more specific label
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants