Jupyter notebook on VSCodeでAthenaに接続
- Thu
- 19:30
- python
本職はアナリストではないでのすが、たまにJupyter notebookを使う場合、notebook自体のエディターは使いにくいのでVisual studio Codeでなんとかならないかと思ったら出来たのでメモ。
ついでにAWS Athenaへクエリーを投げる。やり方はいろいろありましたが、awswranglerを使うと簡単だったのでこれを利用。
awslabs/aws-data-wrangler - https://github.com/awslabs/aws-data-wrangler
Jupyter (ms-toolsai.jupyter Microsoft)
Python自体は3.8をインストールしています。もちろん、awswranglerもインストール。
やってることは簡単で、Athenaへクエリーを投げてその結果をpandasでplotしてるだけ。
サンプルのコード:
後は通常のnotebookと使い方は全く同じで実行ボタンを押すグラフを表示してくれます。便利。
ついでにAWS Athenaへクエリーを投げる。やり方はいろいろありましたが、awswranglerを使うと簡単だったのでこれを利用。
awslabs/aws-data-wrangler - https://github.com/awslabs/aws-data-wrangler
VSCodeにPython/JupyterのExtensionをインストール
Python (ms-python.python Microsoft)Jupyter (ms-toolsai.jupyter Microsoft)
Python自体は3.8をインストールしています。もちろん、awswranglerもインストール。

notebookファイルを作成
VSCodeでファイルを作成・保存する時に拡張子を「.ipynb」にすると自動でJupyter notebookのUIと同じものがVSCode上に表示されます。やってることは簡単で、Athenaへクエリーを投げてその結果をpandasでplotしてるだけ。
サンプルのコード:
import sys, os, array, time import awswrangler as wr import numpy as np import pandas as pd wg = 'primary' db = 'test' query = "SELECT ymd, count FROM test.tbl_test01" df = wr.athena.read_sql_query( query, database=db, workgroup=wg) df.plot(figsize=(5,2), kind='bar', legend=False, title="", x='ymd')
実行してみる
今回はAWSに接続しているので、$HOME/.aws/credentials を準備しておく。後は通常のnotebookと使い方は全く同じで実行ボタンを押すグラフを表示してくれます。便利。

bashでforループ
- Mon
- 16:00
- シェルスクリプト
たまにbashのコマンドラインで複数ファイルを、なんやかんやでワンライナーのforループで処理させたい場合がありますが、たまにやるので ;(セミコロン)の位置を忘れたりするのでメモ。
適当にファイルを作成。
で、ワンライナーのサンプル。
適当にファイルを作成。
$ touch a.txt b.txt c.txt a.log $ ll total 0 drwxr-xr-x 1 user01 user01 4096 Jan 18 15:51 . drwxr-xr-x 1 user01 user01 4096 Jan 18 15:50 .. -rw-r--r-- 1 user01 user01 0 Jan 18 15:51 a.log -rw-r--r-- 1 user01 user01 0 Jan 18 15:51 a.txt -rw-r--r-- 1 user01 user01 0 Jan 18 15:51 b.txt -rw-r--r-- 1 user01 user01 0 Jan 18 15:51 c.txt $
で、ワンライナーのサンプル。
$ for FILE in `ls *.txt`; do echo "FILE=$FILE"; done FILE=a.txt FILE=b.txt FILE=c.txt $
M1 macbookでemacsのbuild
- Mon
- 14:34
- iOS/MacOS
M1 macbookが来たので早速emacsのbuild。
普通にやると下記のようなエラーがでるので、arch -x86_64 をつけてrosetta上でやるとうまくいく。
configure: error: Emacs does not support 'arm-apple-darwin20.1.0' systems.
普通にやると下記のようなエラーがでるので、arch -x86_64 をつけてrosetta上でやるとうまくいく。
configure: error: Emacs does not support 'arm-apple-darwin20.1.0' systems.
$ arch -x86_64 bash The default interactive shell is now zsh. To update your account to use zsh, please run `chsh -s /bin/zsh`. For more details, please visit https://support.apple.com/kb/HT208050. bash-3.2$ ./configure --prefix=${HOME}/local --without-x --with-gnutls=no --with-mailutils checking for xcrun... xcrun checking for make... yes checking for GNU Make... make checking build system type... x86_64-apple-darwin20.1.0 checking host system type... x86_64-apple-darwin20.1.0 checking for gcc... gcc ... $ make /Applications/Xcode.app/Contents/Developer/usr/bin/make -C lib all GEN alloca.h GEN byteswap.h ... bash-3.2$ ./src/emacs --version GNU Emacs 27.1 Copyright (C) 2020 Free Software Foundation, Inc. GNU Emacs comes with ABSOLUTELY NO WARRANTY. You may redistribute copies of GNU Emacs under the terms of the GNU General Public License. For more information about these matters, see the file named COPYING.