跳到主要內容

發表文章

目前顯示的是有「Jupyter Notebook」標籤的文章

Run notebook in Airflow

  The simplest way to achieve this goal is using KubernetesPodOperator to execute papermill command. For example run_notebook = kubernetes_pod_operator.KubernetesPodOperator( task_id=f"run-notebook", name=f"run-notebook", namespace='default', is_delete_operator_pod=True, image_pull_policy="IfNotPresent", startup_timeout_seconds=3600, cmds=['/bin/bash'], arguments=["-c", """ echo y | conda create --name=runenv python=3.8 source /opt/conda/etc/profile.d/conda.sh conda activate runenv conda install ipykernel python -m ipykernel install --user --name=runenv papermill \ "{{dag_run.conf['nbIn']}}" \ "{{dag_run.conf['nbOut']}}" \ ...

Run Notebook from another Notebook

Step 1. Install this package on your environment pip install papermill Step 2. Prepare a kernel that runs your notebook conda create --name=runenv python=3.8 source /opt/conda/etc/profile.d/conda.sh conda activate runenv conda install ipykernel python -m ipykernel install --user --name=runenv Step 3. Run notebook papermill -k runenv \ gs://andy-notebook/in/template.ipynb \ gs://andy-notebook/out/template.ipynb \ -p project_id stage-env \ -p dataset_path gs://andy-data In this example, we use runenv to run notebook gs://andy-notebook/in/template.ipynb and pass parameters "project_id" and "dataset_path" to the notebook. The execution result will be put on GCS (gs://andy-notebook/out/template.ipynb). That's it.

在 Jupyter Notebook 使用 conda 建立的環境

  Step 1. 在  base environment 安裝 nb_conda_kernels (base)$ conda install nb_conda_kernels 如果不行的話就接著做下一步 Step 2. 在新建立的環境下安裝 ipykernel (new-env)$ conda install ipykernel python -m ipykernel install --user --name="My_Project_Name" 其他有用指令 List kernels $ jupyter kernelspec list Remove kernel $ jupyter kernelspec remove [KERNAL_NAME]

淺談 Cloud Dataflow & Apache Beam 處理資料流 | Data Pipeline using Apache Beam and Cloud Dataflow

  前言 在這個資訊爆炸的時代, 資料的產生速度飛快, 面對這些海量的資訊, 若以傳統的方法做資料分析或是分析前的資料處理(Extract Load Transform, ETL), 勢必會面臨到硬體資源不足(記憶體不夠)或是資料處理速度太慢的問題 記憶體不夠時, 將虛擬機做垂直擴展 scaling up 就能夠暫時解決, 但若要加快資料處理的速度, 就會需要一個分散式的資料處理引擎 Spark 或是 Cloud Dataflow, 透過動態的水平擴展 Scaling out 的方式來增加資料處理的 worker 去消化大量資訊 Apache Beam 2016 年時 Google 開源出一套分散式資料處理框架, 定義在 Spark, Flink 以及 Cloud Dataflow 等等分散式資料處理引擎的上層, 讓開發者可以輕鬆地設計資料處理的 pipeline 並運行在分散式的環境裡 它有以下的優點 開源 背後社群龐大, 容易找到資源 移植性 同一個資料處理邏輯可以跑在各大分散式資料處理引擎上 (Flink, Spark, Dataflow...) 擴充性 除了使用 built-in 的 I/O Connector 之外, 開發者也可以自由地實作客製化版本的 Connector 模組 Cloud Dataflow Google 完全託管式的(Fully Managed) 分散式資料處理引擎, No-Ops 的服務特色強調不需要額外的維運人員來維護底層的基礎設施 Dataflow 的上層主要是運行 Apache Beam 的程式碼, 並支援在 Runtime 時動態的彈性擴充底層的運算資源, 因此使用 Dataflow 的開發人員可以更專注地開發資料處理的邏輯以及 pipeline 的設計 開始寫 Apache Beam 程式 Step 1. 建立實驗環境 為了簡化說明, 接下來的示範會跑在 Jupyter Notebook 的環境裡 因此首先會需要在 GCP 上用 Dataflow 的 Notebook 功能建立一個可以跑 Jupyter Notebook 的環境 建立完成後選擇 Open Jupyterlab 進入筆記本 接下來 Step 2. & Step 3. 的程式碼可以直接複製貼到筆記本上執行 Step 2. import 必須的套件 ...

在 Jupyter notebook 中建立 Conda 虛擬環境 | How to add your Conda environment to your Jupyter notebook

前言 相信大家都有以下這個經驗 如果想要在一個獨立且乾淨的環境裡跑 Machine Learning 的實驗,  通常會使用 Anaconda  來建立虛擬環境, 然後當需要的模組都安裝進去後 再執行 activate 將環境給套用進來 但如果是想要在 Jupyter Notebook 裡使用 Anaconda 建立的環境, 那該怎麼做呢!? 首先 Step 1. Create conda env $ conda create --name mycondaenv python=3.7 Step 2. Enter the environment $ activate mycondaenv Step 3. Install required package $ pip install ipykernel Step 4. Install a new kernel $ python -m ipykernel install --user 以上的動作做完之後 就可以在選擇 Kernel 的清單裡刊到剛剛新增的 mycondaenv