{ "cells": [ { "cell_type": "markdown", "id": "19152da9", "metadata": {}, "source": [ "# Download data from FRED" ] }, { "cell_type": "code", "execution_count": 1, "id": "caf31445-5e0e-449a-863b-e80d23abfa87", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np" ] }, { "cell_type": "markdown", "id": "f0401f4d", "metadata": {}, "source": [ "* you need to get a FRED api key from [here](https://fred.stlouisfed.org/docs/api/api_key.html)\n", "* the fredapi package is in the econ108 environment" ] }, { "cell_type": "code", "execution_count": 2, "id": "39ddfd04-e65b-4a0f-87b7-485bf08ece1f", "metadata": {}, "outputs": [], "source": [ "from fredapi import Fred" ] }, { "cell_type": "code", "execution_count": 3, "id": "82082578-dc12-4ddf-a3ac-8d2c119f04ce", "metadata": {}, "outputs": [], "source": [ "fred = Fred(api_key=\"your_fred_api_key\")" ] }, { "cell_type": "markdown", "id": "cc58dac9-b8cc-40dd-80b5-2c0ba019b99c", "metadata": {}, "source": [ "From [FRED](https://fred.stlouisfed.org/)\n", "\n", "\n", "* Real Gross Domestic Product (GDPC1)\n", " Billions of Chained 2012 Dollars,\n", " Seasonally Adjusted Annual Rate\n", "\n", "[link to series](https://fred.stlouisfed.org/series/GDPC1)" ] }, { "cell_type": "code", "execution_count": 4, "id": "1b0b35bb-4c57-4ba6-b73a-3ce533bcdf18", "metadata": {}, "outputs": [], "source": [ "data = fred.get_series(\"GDPC1\")" ] }, { "cell_type": "code", "execution_count": 5, "id": "ab39f1ef-1548-40ad-bc48-a5dda624f135", "metadata": {}, "outputs": [], "source": [ "df = pd.DataFrame(data, columns=['GDPC1']).dropna(axis=0, how='any')" ] }, { "cell_type": "code", "execution_count": 6, "id": "5da8a040-06a1-4cd4-870c-c57eabc32a96", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
GDPC1
1947-01-012034.450
1947-04-012029.024
1947-07-012024.834
1947-10-012056.508
1948-01-012087.442
\n", "
" ], "text/plain": [ " GDPC1\n", "1947-01-01 2034.450\n", "1947-04-01 2029.024\n", "1947-07-01 2024.834\n", "1947-10-01 2056.508\n", "1948-01-01 2087.442" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.head()" ] }, { "cell_type": "markdown", "id": "f5d74c26-82a2-47b5-96f8-82913febad42", "metadata": {}, "source": [ "Some more options..." ] }, { "cell_type": "code", "execution_count": 7, "id": "91b845b1-76ad-4993-b051-cc57a2dd2d81", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "date\n", "2020-10-01 18780.325\n", "2021-01-01 19087.568\n", "2021-04-01 19358.176\n", "2021-07-01 19465.195\n", "2021-10-01 19805.962\n", "Name: value, dtype: object" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = fred.get_series_first_release('GDPC1')\n", "data.tail()" ] }, { "cell_type": "code", "execution_count": 8, "id": "e63c8df6-b25c-4d8c-9e7b-c65fa555435b", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "2020-10-01 18767.778\n", "2021-01-01 19055.655\n", "2021-04-01 19368.310\n", "2021-07-01 19478.893\n", "2021-10-01 19810.572\n", "dtype: float64" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = fred.get_series_latest_release('GDPC1')\n", "data.tail()" ] }, { "cell_type": "code", "execution_count": 9, "id": "fc28e037-e23e-4c4f-bd29-897e066eefe8", "metadata": {}, "outputs": [], "source": [ "data=fred.get_series_as_of_date('GDP', '6/1/2014')" ] }, { "cell_type": "code", "execution_count": 10, "id": "2f49259c-3035-4487-a899-47cd07c9beac", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
realtime_startdatevalue
01992-12-221946-01-01199.7
11996-01-191946-01-01NaT
21997-05-071946-01-01210.4
31999-10-281946-01-01NaT
41992-12-221946-04-01207.7
............
28372014-01-302013-10-0117102.5
28382014-02-282013-10-0117080.7
28392014-03-272013-10-0117089.6
28462014-04-302014-01-0117149.6
28472014-05-292014-01-0117101.3
\n", "

2168 rows × 3 columns

\n", "
" ], "text/plain": [ " realtime_start date value\n", "0 1992-12-22 1946-01-01 199.7\n", "1 1996-01-19 1946-01-01 NaT\n", "2 1997-05-07 1946-01-01 210.4\n", "3 1999-10-28 1946-01-01 NaT\n", "4 1992-12-22 1946-04-01 207.7\n", "... ... ... ...\n", "2837 2014-01-30 2013-10-01 17102.5\n", "2838 2014-02-28 2013-10-01 17080.7\n", "2839 2014-03-27 2013-10-01 17089.6\n", "2846 2014-04-30 2014-01-01 17149.6\n", "2847 2014-05-29 2014-01-01 17101.3\n", "\n", "[2168 rows x 3 columns]" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data" ] }, { "cell_type": "code", "execution_count": 11, "id": "2d9a5e29-231f-410c-b0ed-104f85c6e9aa", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
series idGDPPOTNGDPPOTGDPC1CTMLRNROUNROUSTGDPC1MDLRGDPC1RMLRGDPC1RHLRGDPC1CTLLRGDPC1CTHLRGDPC1RLLR
idGDPPOTNGDPPOTGDPC1CTMLRNROUNROUSTGDPC1MDLRGDPC1RMLRGDPC1RHLRGDPC1CTLLRGDPC1CTHLRGDPC1RLLR
realtime_start2022-02-28 00:00:002022-02-28 00:00:002022-02-28 00:00:002022-02-28 00:00:002022-02-28 00:00:002022-02-28 00:00:002022-02-28 00:00:002022-02-28 00:00:002022-02-28 00:00:002022-02-28 00:00:002022-02-28 00:00:00
realtime_end2022-02-28 00:00:002022-02-28 00:00:002022-02-28 00:00:002022-02-28 00:00:002022-02-28 00:00:002022-02-28 00:00:002022-02-28 00:00:002022-02-28 00:00:002022-02-28 00:00:002022-02-28 00:00:002022-02-28 00:00:00
titleReal Potential Gross Domestic ProductNominal Potential Gross Domestic ProductLonger Run FOMC Summary of Economic Projection...Noncyclical Rate of UnemploymentNatural Rate of Unemployment (Short-Term) (DIS...Longer Run FOMC Summary of Economic Projection...Longer Run FOMC Summary of Economic Projection...Longer Run FOMC Summary of Economic Projection...Longer Run FOMC Summary of Economic Projection...Longer Run FOMC Summary of Economic Projection...Longer Run FOMC Summary of Economic Projection...
observation_start1949-01-01 00:00:001949-01-01 00:00:002009-02-18 00:00:001949-01-01 00:00:001949-01-01 00:00:002015-06-17 00:00:002009-02-18 00:00:002009-02-18 00:00:002009-02-18 00:00:002009-02-18 00:00:002009-02-18 00:00:00
observation_end2031-10-01 00:00:002031-10-01 00:00:002021-12-15 00:00:002031-10-01 00:00:002031-10-01 00:00:002021-12-15 00:00:002021-12-15 00:00:002021-12-15 00:00:002021-12-15 00:00:002021-12-15 00:00:002021-12-15 00:00:00
frequencyQuarterlyQuarterlyNot ApplicableQuarterlyQuarterlyNot ApplicableNot ApplicableNot ApplicableNot ApplicableNot ApplicableNot Applicable
frequency_shortQQNAQQNANANANANANA
unitsBillions of Chained 2012 DollarsBillions of DollarsFourth Quarter to Fourth Quarter Percent ChangePercentPercentFourth Quarter to Fourth Quarter Percent ChangeFourth Quarter to Fourth Quarter Percent ChangeFourth Quarter to Fourth Quarter Percent ChangeFourth Quarter to Fourth Quarter Percent ChangeFourth Quarter to Fourth Quarter Percent ChangeFourth Quarter to Fourth Quarter Percent Change
units_shortBil. of Chn. 2012 $Bil. of $Fourth Qtr. to Fourth Qtr. % Chg.%%Fourth Qtr. to Fourth Qtr. % Chg.Fourth Qtr. to Fourth Qtr. % Chg.Fourth Qtr. to Fourth Qtr. % Chg.Fourth Qtr. to Fourth Qtr. % Chg.Fourth Qtr. to Fourth Qtr. % Chg.Fourth Qtr. to Fourth Qtr. % Chg.
seasonal_adjustmentNot Seasonally AdjustedNot Seasonally AdjustedNot Seasonally AdjustedNot Seasonally AdjustedNot Seasonally AdjustedNot Seasonally AdjustedNot Seasonally AdjustedNot Seasonally AdjustedNot Seasonally AdjustedNot Seasonally AdjustedNot Seasonally Adjusted
seasonal_adjustment_shortNSANSANSANSANSANSANSANSANSANSANSA
last_updated2021-07-01 17:45:02-05:002021-07-01 17:45:02-05:002021-12-15 14:08:07-06:002021-02-01 14:37:05-06:002021-02-01 14:37:07-06:002021-12-15 14:08:15-06:002021-12-15 14:08:34-06:002021-12-15 14:08:16-06:002021-12-15 14:08:39-06:002021-12-15 14:08:38-06:002021-12-15 14:08:39-06:00
popularity72582771601477322
notesReal potential GDP is the CBO’s estimate of th...NoneThe longer-run projections are the rates of gr...Starting with the July, 2021 report: An Update...This series last appeared in the February, 202...The longer-run projections are the rates of gr...The longer-run projections are the rates of gr...The longer-run projections are the rates of gr...The longer-run projections are the rates of gr...The longer-run projections are the rates of gr...The longer-run projections are the rates of gr...
\n", "
" ], "text/plain": [ "series id GDPPOT \\\n", "id GDPPOT \n", "realtime_start 2022-02-28 00:00:00 \n", "realtime_end 2022-02-28 00:00:00 \n", "title Real Potential Gross Domestic Product \n", "observation_start 1949-01-01 00:00:00 \n", "observation_end 2031-10-01 00:00:00 \n", "frequency Quarterly \n", "frequency_short Q \n", "units Billions of Chained 2012 Dollars \n", "units_short Bil. of Chn. 2012 $ \n", "seasonal_adjustment Not Seasonally Adjusted \n", "seasonal_adjustment_short NSA \n", "last_updated 2021-07-01 17:45:02-05:00 \n", "popularity 72 \n", "notes Real potential GDP is the CBO’s estimate of th... \n", "\n", "series id NGDPPOT \\\n", "id NGDPPOT \n", "realtime_start 2022-02-28 00:00:00 \n", "realtime_end 2022-02-28 00:00:00 \n", "title Nominal Potential Gross Domestic Product \n", "observation_start 1949-01-01 00:00:00 \n", "observation_end 2031-10-01 00:00:00 \n", "frequency Quarterly \n", "frequency_short Q \n", "units Billions of Dollars \n", "units_short Bil. of $ \n", "seasonal_adjustment Not Seasonally Adjusted \n", "seasonal_adjustment_short NSA \n", "last_updated 2021-07-01 17:45:02-05:00 \n", "popularity 58 \n", "notes None \n", "\n", "series id GDPC1CTMLR \\\n", "id GDPC1CTMLR \n", "realtime_start 2022-02-28 00:00:00 \n", "realtime_end 2022-02-28 00:00:00 \n", "title Longer Run FOMC Summary of Economic Projection... \n", "observation_start 2009-02-18 00:00:00 \n", "observation_end 2021-12-15 00:00:00 \n", "frequency Not Applicable \n", "frequency_short NA \n", "units Fourth Quarter to Fourth Quarter Percent Change \n", "units_short Fourth Qtr. to Fourth Qtr. % Chg. \n", "seasonal_adjustment Not Seasonally Adjusted \n", "seasonal_adjustment_short NSA \n", "last_updated 2021-12-15 14:08:07-06:00 \n", "popularity 27 \n", "notes The longer-run projections are the rates of gr... \n", "\n", "series id NROU \\\n", "id NROU \n", "realtime_start 2022-02-28 00:00:00 \n", "realtime_end 2022-02-28 00:00:00 \n", "title Noncyclical Rate of Unemployment \n", "observation_start 1949-01-01 00:00:00 \n", "observation_end 2031-10-01 00:00:00 \n", "frequency Quarterly \n", "frequency_short Q \n", "units Percent \n", "units_short % \n", "seasonal_adjustment Not Seasonally Adjusted \n", "seasonal_adjustment_short NSA \n", "last_updated 2021-02-01 14:37:05-06:00 \n", "popularity 71 \n", "notes Starting with the July, 2021 report: An Update... \n", "\n", "series id NROUST \\\n", "id NROUST \n", "realtime_start 2022-02-28 00:00:00 \n", "realtime_end 2022-02-28 00:00:00 \n", "title Natural Rate of Unemployment (Short-Term) (DIS... \n", "observation_start 1949-01-01 00:00:00 \n", "observation_end 2031-10-01 00:00:00 \n", "frequency Quarterly \n", "frequency_short Q \n", "units Percent \n", "units_short % \n", "seasonal_adjustment Not Seasonally Adjusted \n", "seasonal_adjustment_short NSA \n", "last_updated 2021-02-01 14:37:07-06:00 \n", "popularity 60 \n", "notes This series last appeared in the February, 202... \n", "\n", "series id GDPC1MDLR \\\n", "id GDPC1MDLR \n", "realtime_start 2022-02-28 00:00:00 \n", "realtime_end 2022-02-28 00:00:00 \n", "title Longer Run FOMC Summary of Economic Projection... \n", "observation_start 2015-06-17 00:00:00 \n", "observation_end 2021-12-15 00:00:00 \n", "frequency Not Applicable \n", "frequency_short NA \n", "units Fourth Quarter to Fourth Quarter Percent Change \n", "units_short Fourth Qtr. to Fourth Qtr. % Chg. \n", "seasonal_adjustment Not Seasonally Adjusted \n", "seasonal_adjustment_short NSA \n", "last_updated 2021-12-15 14:08:15-06:00 \n", "popularity 14 \n", "notes The longer-run projections are the rates of gr... \n", "\n", "series id GDPC1RMLR \\\n", "id GDPC1RMLR \n", "realtime_start 2022-02-28 00:00:00 \n", "realtime_end 2022-02-28 00:00:00 \n", "title Longer Run FOMC Summary of Economic Projection... \n", "observation_start 2009-02-18 00:00:00 \n", "observation_end 2021-12-15 00:00:00 \n", "frequency Not Applicable \n", "frequency_short NA \n", "units Fourth Quarter to Fourth Quarter Percent Change \n", "units_short Fourth Qtr. to Fourth Qtr. % Chg. \n", "seasonal_adjustment Not Seasonally Adjusted \n", "seasonal_adjustment_short NSA \n", "last_updated 2021-12-15 14:08:34-06:00 \n", "popularity 7 \n", "notes The longer-run projections are the rates of gr... \n", "\n", "series id GDPC1RHLR \\\n", "id GDPC1RHLR \n", "realtime_start 2022-02-28 00:00:00 \n", "realtime_end 2022-02-28 00:00:00 \n", "title Longer Run FOMC Summary of Economic Projection... \n", "observation_start 2009-02-18 00:00:00 \n", "observation_end 2021-12-15 00:00:00 \n", "frequency Not Applicable \n", "frequency_short NA \n", "units Fourth Quarter to Fourth Quarter Percent Change \n", "units_short Fourth Qtr. to Fourth Qtr. % Chg. \n", "seasonal_adjustment Not Seasonally Adjusted \n", "seasonal_adjustment_short NSA \n", "last_updated 2021-12-15 14:08:16-06:00 \n", "popularity 7 \n", "notes The longer-run projections are the rates of gr... \n", "\n", "series id GDPC1CTLLR \\\n", "id GDPC1CTLLR \n", "realtime_start 2022-02-28 00:00:00 \n", "realtime_end 2022-02-28 00:00:00 \n", "title Longer Run FOMC Summary of Economic Projection... \n", "observation_start 2009-02-18 00:00:00 \n", "observation_end 2021-12-15 00:00:00 \n", "frequency Not Applicable \n", "frequency_short NA \n", "units Fourth Quarter to Fourth Quarter Percent Change \n", "units_short Fourth Qtr. to Fourth Qtr. % Chg. \n", "seasonal_adjustment Not Seasonally Adjusted \n", "seasonal_adjustment_short NSA \n", "last_updated 2021-12-15 14:08:39-06:00 \n", "popularity 3 \n", "notes The longer-run projections are the rates of gr... \n", "\n", "series id GDPC1CTHLR \\\n", "id GDPC1CTHLR \n", "realtime_start 2022-02-28 00:00:00 \n", "realtime_end 2022-02-28 00:00:00 \n", "title Longer Run FOMC Summary of Economic Projection... \n", "observation_start 2009-02-18 00:00:00 \n", "observation_end 2021-12-15 00:00:00 \n", "frequency Not Applicable \n", "frequency_short NA \n", "units Fourth Quarter to Fourth Quarter Percent Change \n", "units_short Fourth Qtr. to Fourth Qtr. % Chg. \n", "seasonal_adjustment Not Seasonally Adjusted \n", "seasonal_adjustment_short NSA \n", "last_updated 2021-12-15 14:08:38-06:00 \n", "popularity 2 \n", "notes The longer-run projections are the rates of gr... \n", "\n", "series id GDPC1RLLR \n", "id GDPC1RLLR \n", "realtime_start 2022-02-28 00:00:00 \n", "realtime_end 2022-02-28 00:00:00 \n", "title Longer Run FOMC Summary of Economic Projection... \n", "observation_start 2009-02-18 00:00:00 \n", "observation_end 2021-12-15 00:00:00 \n", "frequency Not Applicable \n", "frequency_short NA \n", "units Fourth Quarter to Fourth Quarter Percent Change \n", "units_short Fourth Qtr. to Fourth Qtr. % Chg. \n", "seasonal_adjustment Not Seasonally Adjusted \n", "seasonal_adjustment_short NSA \n", "last_updated 2021-12-15 14:08:39-06:00 \n", "popularity 2 \n", "notes The longer-run projections are the rates of gr... " ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fred.search('potential gdp').T" ] }, { "cell_type": "code", "execution_count": null, "id": "c673cbc5-80a8-4027-b860-f32d91f2d40b", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.2" } }, "nbformat": 4, "nbformat_minor": 5 }