Share
Embed
JupyterNotebook入門
はんなりPython#3 2018/02/16
JupyterNotebook について入門者向け解説
https://github.com/masayuki14/hannari-python-3
https://hannari-python.connpass.com/event/77366/
Masa
February 18, 2018
Transcript
52 slides
-
Jupyter Notebook 入門 はんなりPython #3 2018/02/16 Navigate : Space /
Arrow Keys | - Menu | - Fullscreen | - Overview | - Blackout | - Speaker | - Help M F O B S ? 1 / 52 -
自己紹介 コミュニティ はんなりPython OSS Gate 主夫 兼 パートタイムプログラマ 兼 スプーキーズアンバサダー
[ GitPitch @ github/masayuki14/hannari-python-3 ] 3 / 52 -
今日する話 1. Jupyter Notebook とは 2. Use Jupyter Notebook 3.
Use Pandas 4. 身近なデータを可視化 [ GitPitch @ github/masayuki14/hannari-python-3 ] 9 / 52 -
Jupyter Notebook とは Project Jupyter 複数のプログラミング言語にまたがるインタラクティ ブコンピューティングのためのサービスを開発する [ GitPitch @
github/masayuki14/hannari-python-3 ] 11 / 52 -
Jupyter Notebook とは Project Jupyter のサービスの1つ ライブコード、方程式、可視化、テキストを含むドキ ュメントを作成して共有できるオープンソースの Webアプリケーション [
GitPitch @ github/masayuki14/hannari-python-3 ] 12 / 52 -
Use Jupyter Notebook by Docker FROM python:latest # Install miniconda
to /miniconda RUN curl -LO 'https://repo.continuum.io/miniconda/Miniconda3-late RUN bash Miniconda3-latest-Linux-x86_64.sh -b -p /miniconda ENV PATH=/miniconda/bin:${PATH} RUN conda update -y conda # install for jupyter notebook RUN conda install -y pandas matplotlib nb_conda RUN conda install -y pyyaml RUN mkdir -p /root/notebook WORKDIR /root/notebook CMD jupyter notebook --ip=0.0.0.0 --allow-root [ GitPitch @ github/masayuki14/hannari-python-3 ] 14 / 52 -
Use Jupyter Notebook Build image Run docker $ docker build
-t jupyter . $ docker run -it --rm -v $(pwd)/notebook:/root/notebook -p 80:888 [ GitPitch @ github/masayuki14/hannari-python-3 ] 15 / 52 -
Use Jupyter Notebook 起動ログに初回アクセスのURLが表示される Copy/paste this URL into your browser
when you connect for the fi to login with a token: http://0.0.0.0:8888/?token=ba4fc6de0d99161f5e144ad4c1167ebf074 [ GitPitch @ github/masayuki14/hannari-python-3 ] 16 / 52 -
Use Jupyter Notebook Hello world def hello(): return 'Hello Jupyter.'
hello() 'Hello Jupyter.' [ GitPitch @ github/masayuki14/hannari-python-3 ] 19 / 52 -
Use Jupyter Notebook グラフを表示 # グラフ表示を有効化 %matplotlib inline import pandas
as pd df = pd.DataFrame([1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987 df.plot() [ GitPitch @ github/masayuki14/hannari-python-3 ] 20 / 52 -
Use Jupyter Notebook Notebook URL 保存した .ipynb ファイルをGitHubにPushすると表 示できる notebook
[ GitPitch @ github/masayuki14/hannari-python-3 ] 23 / 52 -
Use Pandas Pandasをつかおう import pandas as pd [ GitPitch @
github/masayuki14/hannari-python-3 ] 26 / 52 -
Use Pandas データフレームの基本的な使い方 In [1]: import pandas as pd ...:
...: # columnsオプションで列名を指定 ...: df = pd.DataFrame([1,2,3], ...: columns=['value']) ...: df Out[1]: value 0 1 1 2 2 3 [ GitPitch @ github/masayuki14/hannari-python-3 ] 27 / 52 -
Use Pandas タプルで配列を渡す In [2]: df = pd.DataFrame([ ...: ('apple',
100), ('oragne', 230), ('grape', 290), ('ba ...: columns=['name', 'price'] ...: ) ...: df Out[2]: name price 0 apple 100 1 oragne 230 2 grape 290 3 banana 100 [ GitPitch @ github/masayuki14/hannari-python-3 ] 28 / 52 -
Use Pandas ディクショナリで配列を渡す In [3]: df = pd.DataFrame({ ...: 'name':
['apple', 'orange', 'pear', 'peach'], ...: 'price': [120, 150, 230, 360], ...: 'order': [3, 8, 4, 5] ...: }) ...: df Out[3]: name order price 0 apple 3 120 1 orange 8 150 2 pear 4 230 3 peach 5 360 [ GitPitch @ github/masayuki14/hannari-python-3 ] 29 / 52 -
Use Pandas 列の追加 In [4]: df['color'] = ['red', 'orange', 'green',
'pink'] ...: df['total'] = df['order'] * df['price'] ...: df Out[4]: name order price color total 0 apple 3 [ GitPitch @ github/masayuki14/hannari-python-3 ] 30 / 52 -
Use Pandas インデックスの追加 In [5]: df.index = ['Apple', 'Orange', 'Pear',
'Peach'] ...: df Out[5]: name order price color total Apple apple 3 120 red 360 Orange orange 8 150 orange 1200 Pear pear 4 230 green 920 Peach peach 5 360 pink 1800 [ GitPitch @ github/masayuki14/hannari-python-3 ] 31 / 52 -
Use Pandas 列の選択 In [6]: df['price'] Out[6]: Apple 120 Orange
150 Pear 230 Peach 360 Name: price, dtype: int64 [ GitPitch @ github/masayuki14/hannari-python-3 ] 32 / 52 -
Use Pandas 列の選択(複数) In [7]: df[['price', 'color']] Out[7]: price color
Apple 120 red Orange 150 orange Pear 230 green Peach 360 pink [ GitPitch @ github/masayuki14/hannari-python-3 ] 33 / 52 -
Use Pandas head, tail In [8]: df.head(2) Out[8]: name order
price color total Apple apple 3 120 red 360 Orange orange 8 150 orange 1200 [ GitPitch @ github/masayuki14/hannari-python-3 ] 34 / 52 -
Use Pandas インデックス指定 In [9]: df.loc[['Apple', 'Pear']] In [9]: df[1:3]
Out[9]: name order price color total Orange orange 8 150 orange 1200 Pear pear 4 230 green 920 [ GitPitch @ github/masayuki14/hannari-python-3 ] 35 / 52 -
Use Pandas 条件による指定 In [10]: df[df.price > 200] Out[10]: name
order price color total Pear pear 4 230 green 920 Peach peach 5 360 pink 1800 [ GitPitch @ github/masayuki14/hannari-python-3 ] 36 / 52