KaggleでSQL-PFへの道②接続(The Road to SQL Portfolios with Kaggle(2)Connect)

本日のメニューはこちら、Kaggle-Google SQL の接続までを記録します。

  1. [Google] Google CloudにてSQLワークスペースの設置
  2. [Kaggle] Kaggleアカウント作成と使用法復習
  3. [Google] Big Query API有効化
  4. [Google] Cloud Shell 有効化


1.[Google] SQLワークスペース設置

個人アカウントで使っているので問題なし。仕事用アカウントで新規作成しました。何がいいかって、新規だと $300 相当の無料クレジットが付きます。期間は90日かな?APIやShellがいくらになるか不明だけど、サービス試して料金発生したら課金前にデータを消そう。

スムーズに課金移行するためか事前にクレカ登録が必要ですが、カード情報必要ないサンドボックスというサービスもあります。


2.[Kaggle] Kaggleアカウント作成と使用法復習

こちらはGoogle データアナリティクス認定のときにひととおりやってたので、アカウントを掘り起こして(認定後は放置してた)Notebook復習。まあ教材のコピペばっかり、当時の自分の必死さがまぶしい。こちらも仕事用アカウントで新規作成。


3.[Google] Big Query API有効化

ようやくつなぐための段階、Googleさんの説明が詳しいので、APIつなぐのはボタン押して許可するだけです。サービスいろいろあるから選んでね。

何が不安かって、「課金」ですよ。便利なツールはたいてい有料なので、必ず「お金かかります」と書いてあります。このハードルで随分足踏みしてました。ヘタレびびり。

でも大丈夫!前述のとおり、スターターの無料枠使うからめげません。だってMLするわけでもない、AWSみたくリージョン指定して稼働させるわけでもない、裏で動き続ける接続さえ気を付ければ変なことにはならないと判断。


4.[Google] Cloud Shell 有効化

チュートリアルに沿って進みます。Cloud Shell Editor(画面下に現れるコード記述用のダークカラー画面)でもろもろ書いていきます。Python用のBigQuery client libraryと、見やすくしたかったのでpandas データフレームも一緒にインストールしました。

pip install --upgrade pandas-gbq 'google-cloud-bigquery[bqstorage,pandas]'

Shellも_Kaggle NoteBookも、上書くとたくさん行列でてきます。↓

Collecting pandas-gbq
Obtaining dependency information for pandas-gbq from 
---省略---
Successfully installed google-cloud-bigquery-storage-2.24.0 pandas-gbq-0.21.0 pydata-google-auth-1.8.2
Note: you may need to restart the kernel to use updated packages.

Cloud Shellに書き込んだけどKaggleで使いたいので、同時並行でノートブックも更新。結論、Shellで最新にしとかないとKaggleでエラーが出ました。「あなたのバージョン古いよ」みたいな。

しかしNoteBook冒頭で numpyとpandasがテンプレで記述されてるから、これがどう役に立ってるのかは不明。初心者なんてこんなものです。やりながら考える。


次回はKaggleノートブック内の記録。Pythonコード使用して自分のGoogle SQLワークスペースを参照しながら、Notebook内で処理して表示させるまでを試します。


********


Here is today's menu, recording up to the Kaggle-Google SQL connection.

  1. [Google] Setting up an SQL workspace in Google Cloud
  2. [Kaggle] Kaggle account creation and usage review
  3. [Google] Big Query API Activation
  4. [Google] Activate Cloud Shell]


1.[Google] SQL workspace installation

No problem as I use it in my personal account. I created a new account for my work account. What's nice is that it comes with $300 of free credit if you're new. The term is 90 days.

I'm not sure how much the API and shell will cost, but I'll try the service and if I'm charged, I'll delete the data before billing.

To ensure a smooth transition to billing, you will need to register a credit card in advance. There is also a service called Sandbox that does not require credit card information.


2.[Kaggle] Kaggle account creation and usage verification

This had experience during the Google Data Analytics certification. I dug up an account and reviewed the notebook (which I neglected after the certification). Well, all I did was copy and paste the material, and I was confused by my desperation at the time. I also created a new account here with my work account.


3.[Google] Big Query API activation

Finally, we are at the connection stage. Google's explanation is very detailed, so all you have to do to connect to the API is click a button to enable it. There are several services to choose from.

What makes me nervous is the "fee". Most useful tools are paid, so you will always find a note that says "This will cost you money." This hurdle made me hesitate for a long time.

But don't worry! As mentioned above, I will not be discouraged because I will be using the free Starter slot. It's not like I'm doing ML or specifying an expensive region like AWS to run it, so as long as I'm careful about the connections that keep running behind the scenes, I'm sure nothing weird will happen.


4.[Google] Enable Cloud Shell

I followed the tutorial and wrote some stuff in the Cloud Shell Editor (a dark screen for writing code that appears at the bottom of the screen), including the BigQuery client library for Python and a Pandas data frame for better visibility. I installed the BigQuery client library for Python and the pandas data frame.

pip install --upgrade pandas-gbq 'google-cloud-bigquery[bqstorage,pandas]'

Both Shell and _Kaggle NoteBook will give you a lot of results when you write the above code.↓

Collecting pandas-gbq
Obtaining dependency information for pandas-gbq from 
--- omission --
Successfully installed google-cloud-bigquery-storage-2.24.0 pandas-gbq-0.21.0 pydata-google-auth-1.8.2
Note: you may need to restart the kernel to use updated packages.


I wrote it in Cloud Shell but wanted to use it in Kaggle, so I had to update the notebook at the same time.

Bottom line, I got an error in Kaggle if I didn't keep it up to date in Shell. It was like, "Your version is out of date."

However, since numpy and pandas are described in the beginning of NoteBook as templates, I don't know how this helps. Beginners are like this. Think while doing.

Next time, I'll record in Kaggle Notebook, using Python code to reference my Google SQL workspace, and try to process and display it in Notebook.

DATA idm8

Aim for a comprehensive analysis. Data-informed decision making. データ分析/著作権・知的財産マネジメント