|
229 | 229 | "source": [
|
230 | 230 | "### Line plots\n",
|
231 | 231 | "\n",
|
232 |
| - "The `plot()` method will generate line plots for all numeric columns by default:" |
| 232 | + "Let's continue with the example of rolling and expanding calculations:" |
233 | 233 | ]
|
234 | 234 | },
|
235 | 235 | {
|
236 | 236 | "cell_type": "code",
|
237 | 237 | "execution_count": 3,
|
| 238 | + "id": "2e6fc032-939f-4e3a-8cb7-ee57718f0c46", |
| 239 | + "metadata": { |
| 240 | + "editable": true, |
| 241 | + "slideshow": { |
| 242 | + "slide_type": "" |
| 243 | + }, |
| 244 | + "tags": [] |
| 245 | + }, |
| 246 | + "outputs": [ |
| 247 | + { |
| 248 | + "data": { |
| 249 | + "text/html": [ |
| 250 | + "<div>\n", |
| 251 | + "<style scoped>\n", |
| 252 | + " .dataframe tbody tr th:only-of-type {\n", |
| 253 | + " vertical-align: middle;\n", |
| 254 | + " }\n", |
| 255 | + "\n", |
| 256 | + " .dataframe tbody tr th {\n", |
| 257 | + " vertical-align: top;\n", |
| 258 | + " }\n", |
| 259 | + "\n", |
| 260 | + " .dataframe thead th {\n", |
| 261 | + " text-align: right;\n", |
| 262 | + " }\n", |
| 263 | + "</style>\n", |
| 264 | + "<table border=\"1\" class=\"dataframe\">\n", |
| 265 | + " <thead>\n", |
| 266 | + " <tr style=\"text-align: right;\">\n", |
| 267 | + " <th></th>\n", |
| 268 | + " <th>travelers</th>\n", |
| 269 | + " <th>holiday</th>\n", |
| 270 | + " <th>7D MA</th>\n", |
| 271 | + " <th>YTD mean</th>\n", |
| 272 | + " </tr>\n", |
| 273 | + " <tr>\n", |
| 274 | + " <th>date</th>\n", |
| 275 | + " <th></th>\n", |
| 276 | + " <th></th>\n", |
| 277 | + " <th></th>\n", |
| 278 | + " <th></th>\n", |
| 279 | + " </tr>\n", |
| 280 | + " </thead>\n", |
| 281 | + " <tbody>\n", |
| 282 | + " <tr>\n", |
| 283 | + " <th>2020-01-01</th>\n", |
| 284 | + " <td>2311732.0</td>\n", |
| 285 | + " <td>New Year's Day</td>\n", |
| 286 | + " <td>2311732.0</td>\n", |
| 287 | + " <td>2311732.0</td>\n", |
| 288 | + " </tr>\n", |
| 289 | + " <tr>\n", |
| 290 | + " <th>2020-01-02</th>\n", |
| 291 | + " <td>2178656.0</td>\n", |
| 292 | + " <td>New Year's Day</td>\n", |
| 293 | + " <td>2245194.0</td>\n", |
| 294 | + " <td>2245194.0</td>\n", |
| 295 | + " </tr>\n", |
| 296 | + " <tr>\n", |
| 297 | + " <th>2020-01-03</th>\n", |
| 298 | + " <td>2422272.0</td>\n", |
| 299 | + " <td>NaN</td>\n", |
| 300 | + " <td>2304220.0</td>\n", |
| 301 | + " <td>2304220.0</td>\n", |
| 302 | + " </tr>\n", |
| 303 | + " <tr>\n", |
| 304 | + " <th>2020-01-04</th>\n", |
| 305 | + " <td>2210542.0</td>\n", |
| 306 | + " <td>NaN</td>\n", |
| 307 | + " <td>2280800.5</td>\n", |
| 308 | + " <td>2280800.5</td>\n", |
| 309 | + " </tr>\n", |
| 310 | + " <tr>\n", |
| 311 | + " <th>2020-01-05</th>\n", |
| 312 | + " <td>1806480.0</td>\n", |
| 313 | + " <td>NaN</td>\n", |
| 314 | + " <td>2185936.4</td>\n", |
| 315 | + " <td>2185936.4</td>\n", |
| 316 | + " </tr>\n", |
| 317 | + " </tbody>\n", |
| 318 | + "</table>\n", |
| 319 | + "</div>" |
| 320 | + ], |
| 321 | + "text/plain": [ |
| 322 | + " travelers holiday 7D MA YTD mean\n", |
| 323 | + "date \n", |
| 324 | + "2020-01-01 2311732.0 New Year's Day 2311732.0 2311732.0\n", |
| 325 | + "2020-01-02 2178656.0 New Year's Day 2245194.0 2245194.0\n", |
| 326 | + "2020-01-03 2422272.0 NaN 2304220.0 2304220.0\n", |
| 327 | + "2020-01-04 2210542.0 NaN 2280800.5 2280800.5\n", |
| 328 | + "2020-01-05 1806480.0 NaN 2185936.4 2185936.4" |
| 329 | + ] |
| 330 | + }, |
| 331 | + "execution_count": 3, |
| 332 | + "metadata": {}, |
| 333 | + "output_type": "execute_result" |
| 334 | + } |
| 335 | + ], |
| 336 | + "source": [ |
| 337 | + "plot_data = tsa_melted_holiday_travel.drop(columns='year').loc['2020'].assign(\n", |
| 338 | + " **{\n", |
| 339 | + " '7D MA': lambda x: x.travelers.rolling('7D').mean(),\n", |
| 340 | + " 'YTD mean': lambda x: x.travelers.expanding().mean()\n", |
| 341 | + " }\n", |
| 342 | + ")\n", |
| 343 | + "plot_data.head()" |
| 344 | + ] |
| 345 | + }, |
| 346 | + { |
| 347 | + "cell_type": "markdown", |
| 348 | + "id": "616bc44c-4c63-4d9a-9558-8f4de0b5b3e0", |
| 349 | + "metadata": { |
| 350 | + "editable": true, |
| 351 | + "slideshow": { |
| 352 | + "slide_type": "subslide" |
| 353 | + }, |
| 354 | + "tags": [] |
| 355 | + }, |
| 356 | + "source": [ |
| 357 | + "The `plot()` method will generate line plots for all numeric columns by default:" |
| 358 | + ] |
| 359 | + }, |
| 360 | + { |
| 361 | + "cell_type": "code", |
| 362 | + "execution_count": 4, |
238 | 363 | "id": "7d30f224-a4c3-4083-981e-a3340f4a26b0",
|
239 |
| - "metadata": {}, |
| 364 | + "metadata": { |
| 365 | + "editable": true, |
| 366 | + "slideshow": { |
| 367 | + "slide_type": "" |
| 368 | + }, |
| 369 | + "tags": [] |
| 370 | + }, |
240 | 371 | "outputs": [
|
241 | 372 | {
|
242 | 373 | "data": {
|
243 | 374 | "text/plain": [
|
244 | 375 | "<Axes: title={'center': '2020 TSA Traveler Throughput'}, xlabel='date', ylabel='travelers'>"
|
245 | 376 | ]
|
246 | 377 | },
|
247 |
| - "execution_count": 3, |
| 378 | + "execution_count": 4, |
248 | 379 | "metadata": {},
|
249 | 380 | "output_type": "execute_result"
|
250 | 381 | },
|
|
2135 | 2266 | }
|
2136 | 2267 | ],
|
2137 | 2268 | "source": [
|
2138 |
| - "tsa_melted_holiday_travel.drop(columns='year').loc['2020'].assign(\n", |
2139 |
| - " **{\n", |
2140 |
| - " '7D MA': lambda x: x.travelers.rolling('7D').mean(),\n", |
2141 |
| - " 'YTD mean': lambda x: x.travelers.expanding().mean()\n", |
2142 |
| - " }\n", |
2143 |
| - ").plot(title='2020 TSA Traveler Throughput', ylabel='travelers', alpha=0.8)" |
| 2269 | + "plot_data.plot(title='2020 TSA Traveler Throughput', ylabel='travelers', alpha=0.8)" |
2144 | 2270 | ]
|
2145 | 2271 | },
|
2146 | 2272 | {
|
|
2173 | 2299 | },
|
2174 | 2300 | {
|
2175 | 2301 | "cell_type": "code",
|
2176 |
| - "execution_count": 4, |
| 2302 | + "execution_count": 5, |
2177 | 2303 | "id": "babbc6d8-fff4-4505-ad88-8af332416208",
|
2178 | 2304 | "metadata": {},
|
2179 | 2305 | "outputs": [
|
|
2254 | 2380 | "5 74617773.0 7244733.0 NaN"
|
2255 | 2381 | ]
|
2256 | 2382 | },
|
2257 |
| - "execution_count": 4, |
| 2383 | + "execution_count": 5, |
2258 | 2384 | "metadata": {},
|
2259 | 2385 | "output_type": "execute_result"
|
2260 | 2386 | }
|
|
2281 | 2407 | },
|
2282 | 2408 | {
|
2283 | 2409 | "cell_type": "code",
|
2284 |
| - "execution_count": 5, |
| 2410 | + "execution_count": 6, |
2285 | 2411 | "id": "d1776fcf-d50f-44b1-8b11-26675347fec5",
|
2286 | 2412 | "metadata": {},
|
2287 | 2413 | "outputs": [
|
2288 | 2414 | {
|
2289 | 2415 | "data": {
|
2290 | 2416 | "text/plain": [
|
2291 |
| - "<matplotlib.legend.Legend at 0x117d8a960>" |
| 2417 | + "<matplotlib.legend.Legend at 0x12a5c6de0>" |
2292 | 2418 | ]
|
2293 | 2419 | },
|
2294 |
| - "execution_count": 5, |
| 2420 | + "execution_count": 6, |
2295 | 2421 | "metadata": {},
|
2296 | 2422 | "output_type": "execute_result"
|
2297 | 2423 | },
|
|
3735 | 3861 | },
|
3736 | 3862 | {
|
3737 | 3863 | "cell_type": "code",
|
3738 |
| - "execution_count": 6, |
| 3864 | + "execution_count": 7, |
3739 | 3865 | "id": "5f2d78a2-ced4-48c2-b40c-993d72833828",
|
3740 | 3866 | "metadata": {},
|
3741 | 3867 | "outputs": [],
|
|
3758 | 3884 | },
|
3759 | 3885 | {
|
3760 | 3886 | "cell_type": "code",
|
3761 |
| - "execution_count": 7, |
| 3887 | + "execution_count": 8, |
3762 | 3888 | "id": "604d6112-2b33-403d-9383-982ab81e667c",
|
3763 | 3889 | "metadata": {},
|
3764 | 3890 | "outputs": [
|
|
5335 | 5461 | "cell_type": "markdown",
|
5336 | 5462 | "id": "b3baba7d-e807-4e33-9ccb-f21e62af9c1a",
|
5337 | 5463 | "metadata": {
|
| 5464 | + "editable": true, |
5338 | 5465 | "slideshow": {
|
5339 |
| - "slide_type": "fragment" |
| 5466 | + "slide_type": "subslide" |
5340 | 5467 | },
|
5341 | 5468 | "tags": []
|
5342 | 5469 | },
|
|
5356 | 5483 | },
|
5357 | 5484 | {
|
5358 | 5485 | "cell_type": "code",
|
5359 |
| - "execution_count": 8, |
| 5486 | + "execution_count": 9, |
5360 | 5487 | "id": "243f8298-be40-4d6a-a4be-06abb85b0fa6",
|
5361 | 5488 | "metadata": {},
|
5362 | 5489 | "outputs": [],
|
|
5366 | 5493 | },
|
5367 | 5494 | {
|
5368 | 5495 | "cell_type": "code",
|
5369 |
| - "execution_count": 9, |
| 5496 | + "execution_count": 10, |
5370 | 5497 | "id": "7df8b0db-bda6-4a7f-bc63-18fa2a0304f2",
|
5371 | 5498 | "metadata": {},
|
5372 | 5499 | "outputs": [],
|
|
5376 | 5503 | },
|
5377 | 5504 | {
|
5378 | 5505 | "cell_type": "code",
|
5379 |
| - "execution_count": 10, |
| 5506 | + "execution_count": 11, |
5380 | 5507 | "id": "4bfc7ad9-ae6d-440e-b15f-eb3fa16d47ed",
|
5381 | 5508 | "metadata": {},
|
5382 | 5509 | "outputs": [],
|
|
5417 | 5544 | },
|
5418 | 5545 | {
|
5419 | 5546 | "cell_type": "code",
|
5420 |
| - "execution_count": 11, |
| 5547 | + "execution_count": 12, |
5421 | 5548 | "id": "b68a741f-9c37-4925-84b9-615c34ea0297",
|
5422 | 5549 | "metadata": {},
|
5423 | 5550 | "outputs": [
|
5424 | 5551 | {
|
5425 | 5552 | "data": {
|
5426 | 5553 | "text/plain": [
|
5427 |
| - "<seaborn.axisgrid.FacetGrid at 0x117e20980>" |
| 5554 | + "<seaborn.axisgrid.FacetGrid at 0x13f0592b0>" |
5428 | 5555 | ]
|
5429 | 5556 | },
|
5430 |
| - "execution_count": 11, |
| 5557 | + "execution_count": 12, |
5431 | 5558 | "metadata": {},
|
5432 | 5559 | "output_type": "execute_result"
|
5433 | 5560 | },
|
|
6850 | 6977 | },
|
6851 | 6978 | {
|
6852 | 6979 | "cell_type": "code",
|
6853 |
| - "execution_count": 12, |
| 6980 | + "execution_count": 13, |
6854 | 6981 | "id": "46eafd2b-ffef-4aec-9a88-05342ac3fff6",
|
6855 | 6982 | "metadata": {},
|
6856 | 6983 | "outputs": [
|
|
6980 | 7107 | "12 70219363.0 26391765.0 NaN"
|
6981 | 7108 | ]
|
6982 | 7109 | },
|
6983 |
| - "execution_count": 12, |
| 7110 | + "execution_count": 13, |
6984 | 7111 | "metadata": {},
|
6985 | 7112 | "output_type": "execute_result"
|
6986 | 7113 | }
|
|
6995 | 7122 | },
|
6996 | 7123 | {
|
6997 | 7124 | "cell_type": "code",
|
6998 |
| - "execution_count": 13, |
| 7125 | + "execution_count": 14, |
6999 | 7126 | "id": "efccdcd6-2a4f-4c20-856c-9b996da95935",
|
7000 | 7127 | "metadata": {
|
7001 | 7128 | "slideshow": {
|
|
8876 | 9003 | },
|
8877 | 9004 | {
|
8878 | 9005 | "cell_type": "code",
|
8879 |
| - "execution_count": 14, |
| 9006 | + "execution_count": 15, |
8880 | 9007 | "id": "e3379920-013d-4df5-9abc-b321060a6891",
|
8881 | 9008 | "metadata": {},
|
8882 | 9009 | "outputs": [],
|
|
8886 | 9013 | },
|
8887 | 9014 | {
|
8888 | 9015 | "cell_type": "code",
|
8889 |
| - "execution_count": 15, |
| 9016 | + "execution_count": 16, |
8890 | 9017 | "id": "0ec9abff-224b-49cb-ac0c-bd6955b5dcaf",
|
8891 | 9018 | "metadata": {},
|
8892 | 9019 | "outputs": [],
|
|
8896 | 9023 | },
|
8897 | 9024 | {
|
8898 | 9025 | "cell_type": "code",
|
8899 |
| - "execution_count": 16, |
| 9026 | + "execution_count": 17, |
8900 | 9027 | "id": "6d410276-25aa-4c16-9987-4e17930ebced",
|
8901 | 9028 | "metadata": {},
|
8902 | 9029 | "outputs": [],
|
|
8937 | 9064 | },
|
8938 | 9065 | {
|
8939 | 9066 | "cell_type": "code",
|
8940 |
| - "execution_count": 17, |
| 9067 | + "execution_count": 18, |
8941 | 9068 | "id": "681a84a7-6b72-4db8-bfd2-994f98b6494c",
|
8942 | 9069 | "metadata": {},
|
8943 | 9070 | "outputs": [
|
|
10357 | 10484 | },
|
10358 | 10485 | {
|
10359 | 10486 | "cell_type": "code",
|
10360 |
| - "execution_count": 18, |
| 10487 | + "execution_count": 19, |
10361 | 10488 | "id": "cd8a781f-3a17-445f-8ff2-742086122b67",
|
10362 | 10489 | "metadata": {},
|
10363 | 10490 | "outputs": [
|
|
12309 | 12436 | },
|
12310 | 12437 | {
|
12311 | 12438 | "cell_type": "code",
|
12312 |
| - "execution_count": 19, |
| 12439 | + "execution_count": 20, |
12313 | 12440 | "id": "583f952c-2c2e-40ed-9235-fd80a7fe43b7",
|
12314 | 12441 | "metadata": {},
|
12315 | 12442 | "outputs": [],
|
|
12319 | 12446 | },
|
12320 | 12447 | {
|
12321 | 12448 | "cell_type": "code",
|
12322 |
| - "execution_count": 20, |
| 12449 | + "execution_count": 21, |
12323 | 12450 | "id": "0b182f1a-33b0-4dde-9d54-e55d7bfeeae3",
|
12324 | 12451 | "metadata": {},
|
12325 | 12452 | "outputs": [],
|
|
12329 | 12456 | },
|
12330 | 12457 | {
|
12331 | 12458 | "cell_type": "code",
|
12332 |
| - "execution_count": 21, |
| 12459 | + "execution_count": 22, |
12333 | 12460 | "id": "07394de8-c5fa-4c90-ac5c-e5b6452838c7",
|
12334 | 12461 | "metadata": {},
|
12335 | 12462 | "outputs": [],
|
|
0 commit comments