Slide 1

Slide 1 text

Jupyter Notebook 入門 はんなりPython #3 2018/02/16 Navigate : Space / Arrow Keys | - Menu | - Fullscreen | - Overview | - Blackout | - Speaker | - Help M F O B S ?  1 / 52

Slide 2

Slide 2 text

自己紹介 森崎雅之 @masayuki14 Follow me !! [ GitPitch @ github/masayuki14/hannari-python-3 ]  2 / 52

Slide 3

Slide 3 text

自己紹介 コミュニティ はんなりPython OSS Gate 主夫 兼 パートタイムプログラマ 兼 スプーキーズアンバサダー [ GitPitch @ github/masayuki14/hannari-python-3 ]  3 / 52

Slide 4

Slide 4 text

スプーキーズ@京都 ソーシャルゲーム ✕ ボードゲーム [ GitPitch @ github/masayuki14/hannari-python-3 ]  4 / 52

Slide 5

Slide 5 text

スプーキーズ@京都 社内勉強会やってます WebRTCを活用する Docker勉強会 ゲームAIを作って競い合う構想 [ GitPitch @ github/masayuki14/hannari-python-3 ]  5 / 52

Slide 6

Slide 6 text

スプーキーズ@京都 エンジニア勉強会 #1 3/23(金) connpass 79323 [ GitPitch @ github/masayuki14/hannari-python-3 ]  6 / 52

Slide 7

Slide 7 text

スプーキーズ@京都 Webエンジニア募集中 [ GitPitch @ github/masayuki14/hannari-python-3 ]  7 / 52

Slide 8

Slide 8 text

今日する話 Jupyter Notebook 入門 [ GitPitch @ github/masayuki14/hannari-python-3 ]  8 / 52

Slide 9

Slide 9 text

今日する話 1. Jupyter Notebook とは 2. Use Jupyter Notebook 3. Use Pandas 4. 身近なデータを可視化 [ GitPitch @ github/masayuki14/hannari-python-3 ]  9 / 52

Slide 10

Slide 10 text

Jupyter Notebook とは [ GitPitch @ github/masayuki14/hannari-python-3 ]  10 / 52

Slide 11

Slide 11 text

Jupyter Notebook とは Project Jupyter 複数のプログラミング言語にまたがるインタラクティ ブコンピューティングのためのサービスを開発する [ GitPitch @ github/masayuki14/hannari-python-3 ]  11 / 52

Slide 12

Slide 12 text

Jupyter Notebook とは Project Jupyter のサービスの1つ ライブコード、方程式、可視化、テキストを含むドキ ュメントを作成して共有できるオープンソースの Webアプリケーション [ GitPitch @ github/masayuki14/hannari-python-3 ]  12 / 52

Slide 13

Slide 13 text

Use Jupyter Notebook [ GitPitch @ github/masayuki14/hannari-python-3 ]  13 / 52

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

Use Jupyter Notebook にアクセス!! http://localhost/? token=ba4fc6de0d99161f5e144ad4c1167ebf074ddc29b916 [ GitPitch @ github/masayuki14/hannari-python-3 ]  17 / 52

Slide 18

Slide 18 text

Use Jupyter Notebook [ GitPitch @ github/masayuki14/hannari-python-3 ]  18 / 52

Slide 19

Slide 19 text

Use Jupyter Notebook Hello world def hello(): return 'Hello Jupyter.' hello() 'Hello Jupyter.' [ GitPitch @ github/masayuki14/hannari-python-3 ]  19 / 52

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

Use Jupyter Notebook データの特徴 fibo_pd.describe() [ GitPitch @ github/masayuki14/hannari-python-3 ]  21 / 52

Slide 22

Slide 22 text

Use Jupyter Notebook Markdown Markdownでメモなどを残せる LaTeXで数式を書ける [ GitPitch @ github/masayuki14/hannari-python-3 ]  22 / 52

Slide 23

Slide 23 text

Use Jupyter Notebook Notebook URL 保存した .ipynb ファイルをGitHubにPushすると表 示できる notebook [ GitPitch @ github/masayuki14/hannari-python-3 ]  23 / 52

Slide 24

Slide 24 text

Use Pandas [ GitPitch @ github/masayuki14/hannari-python-3 ]  24 / 52

Slide 25

Slide 25 text

Use Pandas 1次元データ構造のシリーズ(Series) 2次元データ構造のデータフレーム(DataFrame) [ GitPitch @ github/masayuki14/hannari-python-3 ]  25 / 52

Slide 26

Slide 26 text

Use Pandas Pandasをつかおう import pandas as pd [ GitPitch @ github/masayuki14/hannari-python-3 ]  26 / 52

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

Use Pandas 対話的、探索的にデータを操作できる https://git.io/vA8Uj [ GitPitch @ github/masayuki14/hannari-python-3 ]  37 / 52

Slide 38

Slide 38 text

身近なデータを可視化 [ GitPitch @ github/masayuki14/hannari-python-3 ]  38 / 52

Slide 39

Slide 39 text

身近なデータを可視化 Pandas でデータ操作だけじゃつ まらない [ GitPitch @ github/masayuki14/hannari-python-3 ]  39 / 52

Slide 40

Slide 40 text

身近なデータを可視化 そうだ可視化しよう [ GitPitch @ github/masayuki14/hannari-python-3 ]  40 / 52

Slide 41

Slide 41 text

身近なデータを可視化 グラフを書いてみよう [ GitPitch @ github/masayuki14/hannari-python-3 ]  41 / 52

Slide 42

Slide 42 text

身近なデータを可視化 今年は雪が多い 福井県出身なんです [ GitPitch @ github/masayuki14/hannari-python-3 ]  42 / 52

Slide 43

Slide 43 text

[ GitPitch @ github/masayuki14/hannari-python-3 ]  43 / 52

Slide 44

Slide 44 text

身近なデータを可視化 昭和38年、昭和56年と比較する [ GitPitch @ github/masayuki14/hannari-python-3 ]  44 / 52

Slide 45

Slide 45 text

身近なデータを可視化 気象庁の観測データをDL http://www.data.jma.go.jp/gmd/risk/obsdl/index.php [ GitPitch @ github/masayuki14/hannari-python-3 ]  45 / 52

Slide 46

Slide 46 text

身近なデータを可視化 最深積雪をグラフにする [ GitPitch @ github/masayuki14/hannari-python-3 ]  46 / 52

Slide 47

Slide 47 text

身近なデータを可視化 年別の最深積雪 [ GitPitch @ github/masayuki14/hannari-python-3 ]  47 / 52

Slide 48

Slide 48 text

身近なデータを可視化 昭和38年 (1963年) [ GitPitch @ github/masayuki14/hannari-python-3 ]  48 / 52

Slide 49

Slide 49 text

身近なデータを可視化 昭和56年 (1981年) [ GitPitch @ github/masayuki14/hannari-python-3 ]  49 / 52

Slide 50

Slide 50 text

身近なデータを可視化 平成30年 (2018年) [ GitPitch @ github/masayuki14/hannari-python-3 ]  50 / 52

Slide 51

Slide 51 text

まとめ Jupyter Notebook を使うことは データサイエンスのはじめの一歩 [ GitPitch @ github/masayuki14/hannari-python-3 ]  51 / 52

Slide 52

Slide 52 text

ありがとうございました 発表資料 https://git.io/vAl8 [ GitPitch @ github/masayuki14/hannari-python-3 ]  52 / 52