|
11 | 11 | "In this notebook, we will work with the following:\n", |
12 | 12 | "\n", |
13 | 13 | "- API access.\n", |
14 | | - "- pandas-datareader\n", |
| 14 | + " - NYTimes API.\n", |
| 15 | + " - FRED API.\n", |
15 | 16 | "- Commercial databases.\n", |
16 | 17 | "- SQL." |
17 | 18 | ] |
|
27 | 28 | "\n", |
28 | 29 | "import plotly.express as px\n", |
29 | 30 | "import pandas as pd\n", |
30 | | - "import pandas_datareader as pdr\n", |
| 31 | + "import pyfredapi as pf\n", |
31 | 32 | "from pynytimes import NYTAPI" |
32 | 33 | ] |
33 | 34 | }, |
|
130 | 131 | "cell_type": "markdown", |
131 | 132 | "metadata": {}, |
132 | 133 | "source": [ |
133 | | - "# pandas-datareader\n", |
| 134 | + "# FRED\n", |
134 | 135 | "\n", |
135 | | - "The `pandas-datareader` package provides access to a number of APIs that have a huge amount of data.\n", |
136 | | - "It is under very active development, so you may see new sources appear.\n", |
| 136 | + "Another API example is FRED, the Federal Reserve Economic Data system.\n", |
| 137 | + "It's a fairly typical API in that you register for a key, and then you can access the data.\n", |
137 | 138 | "\n", |
138 | | - "Below, we have a simple example of getting the 10-year US Treasury bond yield at monthly resolution from FRED, the Federal Reserve Economic Data system." |
| 139 | + "Let's try a less-guided example of obtaining your API key.\n", |
| 140 | + "\n", |
| 141 | + "- [FRED API key](https://fred.stlouisfed.org/docs/api/api_key.html)\n", |
| 142 | + "- [pyfredapi documentation](https://pyfredapi.readthedocs.io/en/latest/)\n", |
| 143 | + "\n", |
| 144 | + "Below, we have a simple example of getting the 10-year US Treasury bond yield at monthly resolution from FRED." |
139 | 145 | ] |
140 | 146 | }, |
141 | 147 | { |
|
144 | 150 | "metadata": {}, |
145 | 151 | "outputs": [], |
146 | 152 | "source": [ |
147 | | - "start = datetime.datetime(2012, 1, 1)\n", |
148 | | - "end = datetime.datetime(2023, 12, 31)\n", |
149 | | - "\n", |
150 | | - "fred_gs10 = pdr.DataReader(\"GS10\", \"fred\", start, end).reset_index()\n", |
| 153 | + "fred_gs10 = pf.get_series(\"GS10\")\n", |
151 | 154 | "fred_gs10.head()" |
152 | 155 | ] |
153 | 156 | }, |
|
157 | 160 | "metadata": {}, |
158 | 161 | "outputs": [], |
159 | 162 | "source": [ |
160 | | - "px.line(fred_gs10, x=\"DATE\", y=\"GS10\", template=\"plotly_dark\").show()" |
| 163 | + "px.line(\n", |
| 164 | + " fred_gs10[fred_gs10[\"date\"] >= pd.to_datetime(\"2012-01-01\")],\n", |
| 165 | + " x=\"date\",\n", |
| 166 | + " y=\"value\",\n", |
| 167 | + " template=\"plotly_dark\",\n", |
| 168 | + ").show()" |
161 | 169 | ] |
162 | 170 | }, |
163 | 171 | { |
|
166 | 174 | "metadata": {}, |
167 | 175 | "outputs": [], |
168 | 176 | "source": [ |
169 | | - "len(fred_gs10)" |
| 177 | + "len(fred_gs10[fred_gs10[\"date\"] >= pd.to_datetime(\"2012-01-01\")])" |
170 | 178 | ] |
171 | 179 | }, |
172 | 180 | { |
|
207 | 215 | "\n", |
208 | 216 | "If time permits, choose one of the following as a group.\n", |
209 | 217 | "\n", |
210 | | - "1. Experiment with other searches with the NY Times API by adapting the code above. You may want to create new cells below.\n", |
211 | | - "1. Look at the [pandas-datareader documentation](https://pandas-datareader.readthedocs.io/en/latest/), and decide on another dataset to try out. Like the option above, you may want to create new cells." |
| 218 | + "1. Experiment with other searches with the NY Times API by adapting the code above. You may want to create new cells below." |
212 | 219 | ] |
213 | 220 | } |
214 | 221 | ], |
|
228 | 235 | "name": "python", |
229 | 236 | "nbconvert_exporter": "python", |
230 | 237 | "pygments_lexer": "ipython3", |
231 | | - "version": "3.11.4" |
| 238 | + "version": "3.12.2" |
232 | 239 | }, |
233 | 240 | "vscode": { |
234 | 241 | "interpreter": { |
|
0 commit comments