|
6 | 6 | "metadata": {}, |
7 | 7 | "outputs": [], |
8 | 8 | "source": [ |
| 9 | + "# Install the google-cloud-bigquery and pydata-google-auth packages\n", |
| 10 | + "# to use this code snippet.\n", |
| 11 | + "import google.cloud.bigquery\n", |
9 | 12 | "import google.cloud.bigquery.magics\n", |
10 | 13 | "import pydata_google_auth" |
11 | 14 | ] |
|
16 | 19 | "metadata": {}, |
17 | 20 | "outputs": [], |
18 | 21 | "source": [ |
19 | | - "credentials = pydata_google_auth.get_user_credentials([\"https://www.googleapis.com/auth/cloud-platform\"])" |
| 22 | + "# In the cell output, open the link to authenticate with your\n", |
| 23 | + "# Google credentials.\n", |
| 24 | + "credentials = pydata_google_auth.get_user_credentials([\"https://www.googleapis.com/auth/cloud-platform\"])\n", |
| 25 | + "project_id = \"my-project-id\"" |
20 | 26 | ] |
21 | 27 | }, |
22 | 28 | { |
|
25 | 31 | "metadata": {}, |
26 | 32 | "outputs": [], |
27 | 33 | "source": [ |
28 | | - "google.cloud.bigquery.magics.context.project = \"my-project-id\"\n", |
| 34 | + "# Configure the magics to use your credentials and project.\n", |
| 35 | + "google.cloud.bigquery.magics.context.project = project_id\n", |
29 | 36 | "google.cloud.bigquery.magics.context.credentials = credentials" |
30 | 37 | ] |
31 | 38 | }, |
|
52 | 59 | "LIMIT 3" |
53 | 60 | ] |
54 | 61 | }, |
| 62 | + { |
| 63 | + "cell_type": "code", |
| 64 | + "execution_count": null, |
| 65 | + "metadata": {}, |
| 66 | + "outputs": [], |
| 67 | + "source": [ |
| 68 | + "# Configure a BigQuery client to use your credentials and project.\n", |
| 69 | + "bqclient = google.cloud.bigquery.Client()" |
| 70 | + ] |
| 71 | + }, |
| 72 | + { |
| 73 | + "cell_type": "code", |
| 74 | + "execution_count": null, |
| 75 | + "metadata": {}, |
| 76 | + "outputs": [], |
| 77 | + "source": [ |
| 78 | + "query_job = bqclient.query(\n", |
| 79 | + "\"\"\"SELECT name, SUM(number) as count\n", |
| 80 | + "FROM `bigquery-public-data.usa_names.usa_1910_current`\n", |
| 81 | + "GROUP BY name\n", |
| 82 | + "ORDER BY count DESC\n", |
| 83 | + "LIMIT 3\n", |
| 84 | + "\"\"\")\n", |
| 85 | + "query_job.result()" |
| 86 | + ] |
| 87 | + }, |
| 88 | + { |
| 89 | + "cell_type": "code", |
| 90 | + "execution_count": null, |
| 91 | + "metadata": {}, |
| 92 | + "outputs": [], |
| 93 | + "source": [ |
| 94 | + "query_job.to_dataframe()" |
| 95 | + ] |
| 96 | + }, |
55 | 97 | { |
56 | 98 | "cell_type": "code", |
57 | 99 | "execution_count": null, |
|
62 | 104 | ], |
63 | 105 | "metadata": { |
64 | 106 | "kernelspec": { |
65 | | - "display_name": "Python 3", |
| 107 | + "display_name": "Python 3 (ipykernel)", |
66 | 108 | "language": "python", |
67 | 109 | "name": "python3" |
68 | 110 | }, |
|
76 | 118 | "name": "python", |
77 | 119 | "nbconvert_exporter": "python", |
78 | 120 | "pygments_lexer": "ipython3", |
79 | | - "version": "3.7.3" |
| 121 | + "version": "3.9.5" |
80 | 122 | } |
81 | 123 | }, |
82 | 124 | "nbformat": 4, |
|
0 commit comments