コンテンツにスキップ

JupyterノートブックとJupyter Labは、データの分析、探索、説明、レポート作成のための優れた対話機能を提供します。PlaidCloudでは、ノートブックで情報を直接利用できます。

PlaidCloudは、有効化されている場合、各テナントのワークスペース内でJupyterHubを提供します。以下のドキュメントは、デスクトップまたは別のサーバーにJupyterを個別にセットアップする際の手順です。

Jupyterノートブックのインストール

Section titled “Jupyterノートブックのインストール”

ここでは、Jupyterノートブックのインストールが正常に動作していることを前提とします。

スタンドアロンのJupyterノートブックのインストール

Section titled “スタンドアロンのJupyterノートブックのインストール”

Jupyterノートブックをローカルにインストールする方法の詳細は、Jupyterのインストールに関するドキュメントをご覧ください。

VS Codeには、ノートブックをVS Code内で直接実行できる拡張機能もあります。Visual Studio Marketplaceから拡張機能をインストールします。

PlaidCloudユーティリティのインストール

Section titled “PlaidCloudユーティリティのインストール”

PlaidCloudには、標準的なOAuthとJSON-RPCリクエストでもアクセスできますが、アクセスを簡単にするために、事前構築済みのライブラリの使用をおすすめします。さらに、PlaidCloudユーティリティライブラリには、Pandasデータフレームで使える便利なデータヘルパーが含まれています。

PlaidCloudユーティリティをインストールするには、次のpipインストールを実行します。

ターミナルウィンドウ
pip install plaidcloud-rpc@git+https://github.com/PlaidCloud/plaid-rpc.git@v1.4.0#egg=plaidcloud-rpc
ターミナルウィンドウ
pip install plaidcloud-utilities@git+https://github.com/PlaidCloud/plaid-utilities.git@v1.5.2#egg=plaidcloud-utilities

OAuthトークンの取得方法と、自動認証のためのシステム設定については、OAuthの設定をご覧ください。

Jupyterノートブックのユーザーインターフェイスを開く

Section titled “Jupyterノートブックのユーザーインターフェイスを開く”

ノートブックサーバーを起動して始めます。

Jupyterノートブックサーバーにサインインしたら、UIから新しいノートブックを作成します。

空のノートブックが開きます。

APIエンドポイント経由でPlaidCloudと通信するための接続を作成します。

from plaidcloud.utilities.connect import PlaidConnection
conn = PlaidConnection()

ローカルのテーブルオブジェクトを作成してクエリを実行すると、結果が自動的にPandasのデータフレームに格納されます。

tbl_sf_cust_master = conn.get_table('Salesforce_Customer_Master') # This gets a table object
df_sf_cust_master = conn.get_data(tbl_sf_cust_master) # This retrieves all the data into a dataframe

同じテーブルオブジェクトを使って、標準的なSQLAlchemy構文でより高度なクエリを記述することもできます。

df_sf_cust_master_w_sales = conn.get_data(
tbl_sf_cust_master.select().with_only_columns(
[tbl_sf_cust_master.c.Id, tbl_sf_cust_master.c.CurrencyIsoCode, tbl_sf_cust_master.c.SyDSalesRegion]
).where(
tbl_sf_cust_master.c.TotalSalesPast3Years > 0
)
)