Caution
I'm new to GCP, python and jupyter. I was very happy to be able to move it while going around, so I posted it. I would appreciate it if you could let me know if you have any mistakes.
-[GCP] AI Platform Notebooks has been officially released, so try using it. -[BigQuery] Did you know that you can use CREATE statements? Create table with SQL
Open the GCP console
https://console.cloud.google.com/
Select "BigQuery" from the side menu
Click "Create Dataset"
I tried to create it with the dataset ID set to "test_data_set"
Easily create tables and data for testing
Paste the following query into the query editor and click Run
create table test_data_set.t (i INT64);
insert into test_data_set.t values (1),(2),(5),(7),(12);
Now that we have the data, let's take a look at it using Jupyter.
Select Side Menu> "AI Platform"> "Notebook"
I selected "New Instance"> "Python 2 and 3"
You can select the region etc. and the estimated amount is also displayed, but this time I will delete the instance as soon as I try it, so I pressed "Create" with the default settings
Click "Open JUPYTER LAB"
Jupyter Lab opens
When I first tried to get bigquery data
"UserWarning: Cannot create BigQuery Storage client, the dependency google-cloud-bigquery-storage is not installed."
I got an error, so install google-cloud-bigquery-storage
first
Click "Console"
Install google-cloud-bigquery-storage
$ pip install google-cloud-bigquery-storage
Press Python 3 to create a new notebook
By default, JupyterLab has a file called /tutorials/bigquery/BigQuery basics.ipynb
and there is an easy-to-understand explanation, so I tried to easily create a process of data acquisition from bigquery by referring to that area.
from google.cloud import bigquery
client = bigquery.Client(location="US")
query = """
select *
from test_data_set.t
order by i
"""
query_job = client.query(
query,
# Location must match that of the dataset(s) referenced in the query.
location="US",
) # API request - starts the query
dv = query_job.to_dataframe()
print(df)
df.plot()
Press "▷" to execute
I was able to display the data of the bigquery I made first as a graph!
There will be a charge at the end, so stop with "Stop"
Thank you for watching until the end m (_ _) m
Recommended Posts