|
142 | 142 | { |
143 | 143 | "data": { |
144 | 144 | "application/vnd.jupyter.widget-view+json": { |
145 | | - "model_id": "710b4e9c06df4faf82011dd676e9d9a5", |
| 145 | + "model_id": "8fcad7b7e408422cae71d519cd2d4980", |
146 | 146 | "version_major": 2, |
147 | 147 | "version_minor": 1 |
148 | 148 | }, |
|
166 | 166 | } |
167 | 167 | ], |
168 | 168 | "source": [ |
169 | | - "df" |
| 169 | + "df.set_index(\"name\")" |
170 | 170 | ] |
171 | 171 | }, |
172 | 172 | { |
|
205 | 205 | { |
206 | 206 | "data": { |
207 | 207 | "application/vnd.jupyter.widget-view+json": { |
208 | | - "model_id": "62661c02a1a742d79e53dcb047343e86", |
| 208 | + "model_id": "06cb98c577514d5c9654a7792d93f8e6", |
209 | 209 | "version_major": 2, |
210 | 210 | "version_minor": 1 |
211 | 211 | }, |
|
305 | 305 | { |
306 | 306 | "data": { |
307 | 307 | "application/vnd.jupyter.widget-view+json": { |
308 | | - "model_id": "b92000a35d0c4b8a9a8aaef4784e94dd", |
| 308 | + "model_id": "1672f826f7a347e38539dbb5fb72cd43", |
309 | 309 | "version_major": 2, |
310 | 310 | "version_minor": 1 |
311 | 311 | }, |
|
326 | 326 | "small_widget" |
327 | 327 | ] |
328 | 328 | }, |
329 | | - { |
330 | | - "cell_type": "markdown", |
331 | | - "id": "a9d5d13b", |
332 | | - "metadata": {}, |
333 | | - "source": [ |
334 | | - "### Handling of Invalid Row Count\n", |
335 | | - "In cases where the total number of rows cannot be determined, `row_count` will be `None`. The widget will display 'Page X of many', and you can navigate forward until you reach the end of the available data. If you navigate beyond the last page, the widget will automatically return to the last valid page." |
336 | | - ] |
337 | | - }, |
338 | 329 | { |
339 | 330 | "cell_type": "markdown", |
340 | 331 | "id": "added-cell-2", |
|
354 | 345 | "data": { |
355 | 346 | "text/html": [ |
356 | 347 | "✅ Completed. \n", |
357 | | - " Query processed 85.9 kB in 13 seconds of slot time.\n", |
| 348 | + " Query processed 85.9 kB in 12 seconds of slot time.\n", |
358 | 349 | " " |
359 | 350 | ], |
360 | 351 | "text/plain": [ |
|
389 | 380 | { |
390 | 381 | "data": { |
391 | 382 | "application/vnd.jupyter.widget-view+json": { |
392 | | - "model_id": "2620318ca07e405fa7ce950a2d931e6a", |
| 383 | + "model_id": "127a2e356b834c18b6f07c58ee2c4228", |
393 | 384 | "version_major": 2, |
394 | 385 | "version_minor": 1 |
395 | 386 | }, |
|
424 | 415 | " LIMIT 5;\n", |
425 | 416 | "\"\"\")" |
426 | 417 | ] |
| 418 | + }, |
| 419 | + { |
| 420 | + "cell_type": "markdown", |
| 421 | + "id": "multi-index-display-markdown", |
| 422 | + "metadata": {}, |
| 423 | + "source": [ |
| 424 | + "## Display Multi-Index DataFrame in anywidget mode\n", |
| 425 | + "This section demonstrates how BigFrames can display a DataFrame with multiple levels of indexing (a \"multi-index\") when using the `anywidget` display mode." |
| 426 | + ] |
| 427 | + }, |
| 428 | + { |
| 429 | + "cell_type": "code", |
| 430 | + "execution_count": 11, |
| 431 | + "id": "ad7482aa", |
| 432 | + "metadata": {}, |
| 433 | + "outputs": [ |
| 434 | + { |
| 435 | + "data": { |
| 436 | + "text/html": [ |
| 437 | + "✅ Completed. \n", |
| 438 | + " Query processed 483.3 GB in 51 minutes of slot time. [<a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=bigframes-dev&j=bq:US:3eace7c0-7776-48d6-925c-965be33d8738&page=queryresults\">Job bigframes-dev:US.3eace7c0-7776-48d6-925c-965be33d8738 details</a>]\n", |
| 439 | + " " |
| 440 | + ], |
| 441 | + "text/plain": [ |
| 442 | + "<IPython.core.display.HTML object>" |
| 443 | + ] |
| 444 | + }, |
| 445 | + "metadata": {}, |
| 446 | + "output_type": "display_data" |
| 447 | + }, |
| 448 | + { |
| 449 | + "data": { |
| 450 | + "text/html": [ |
| 451 | + "✅ Completed. \n", |
| 452 | + " Query processed 124.4 MB in 7 seconds of slot time. [<a target=\"_blank\" href=\"https://console.cloud.google.com/bigquery?project=bigframes-dev&j=bq:US:job_UJ5cx4R1jW5cNxq_1H1x-9-ATfqS&page=queryresults\">Job bigframes-dev:US.job_UJ5cx4R1jW5cNxq_1H1x-9-ATfqS details</a>]\n", |
| 453 | + " " |
| 454 | + ], |
| 455 | + "text/plain": [ |
| 456 | + "<IPython.core.display.HTML object>" |
| 457 | + ] |
| 458 | + }, |
| 459 | + "metadata": {}, |
| 460 | + "output_type": "display_data" |
| 461 | + }, |
| 462 | + { |
| 463 | + "data": { |
| 464 | + "application/vnd.jupyter.widget-view+json": { |
| 465 | + "model_id": "3f9652b5fdc0441eac2b05ab36d571d0", |
| 466 | + "version_major": 2, |
| 467 | + "version_minor": 1 |
| 468 | + }, |
| 469 | + "text/plain": [ |
| 470 | + "TableWidget(page_size=10, row_count=3967869, table_html='<table border=\"1\" class=\"dataframe table table-stripe…" |
| 471 | + ] |
| 472 | + }, |
| 473 | + "metadata": {}, |
| 474 | + "output_type": "display_data" |
| 475 | + }, |
| 476 | + { |
| 477 | + "data": { |
| 478 | + "text/html": [], |
| 479 | + "text/plain": [ |
| 480 | + "Computation deferred. Computation will process 513.5 GB" |
| 481 | + ] |
| 482 | + }, |
| 483 | + "execution_count": 11, |
| 484 | + "metadata": {}, |
| 485 | + "output_type": "execute_result" |
| 486 | + } |
| 487 | + ], |
| 488 | + "source": [ |
| 489 | + "import datetime\n", |
| 490 | + "\n", |
| 491 | + " # Read the PyPI downloads dataset\n", |
| 492 | + "pypi_df = bpd.read_gbq(\"bigquery-public-data.pypi.file_downloads\")\n", |
| 493 | + "\n", |
| 494 | + "# Filter for the last 7 days to reduce the data size for this example\n", |
| 495 | + "seven_days_ago = datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta(days=7)\n", |
| 496 | + "pypi_df_recent = pypi_df[pypi_df[\"timestamp\"] > seven_days_ago]\n", |
| 497 | + " \n", |
| 498 | + "# Create a multi-index by grouping by date and project\n", |
| 499 | + "pypi_df_recent['date'] = pypi_df_recent['timestamp'].dt.date\n", |
| 500 | + "multi_index_df = pypi_df_recent.groupby([\"date\", \"project\"]).size().to_frame(\"downloads\")\n", |
| 501 | + " \n", |
| 502 | + "# Display the DataFrame with the multi-index\n", |
| 503 | + "multi_index_df" |
| 504 | + ] |
427 | 505 | } |
428 | 506 | ], |
429 | 507 | "metadata": { |
|
0 commit comments