Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Beginning PyData with Django and Jupyter
Search
kuma127
September 17, 2019
Programming
3
5.4k
Beginning PyData with Django and Jupyter
PyCon JP 2019 9/17 16:15~
kuma127
September 17, 2019
Tweet
Share
More Decks by kuma127
See All by kuma127
私と#pyhack
kuma127
0
220
配信チームの準備と当日進行について
kuma127
0
320
石川雅規のことをもっと知ってもらいたいLT
kuma127
0
1.4k
DjangoとJupyterで捗るPyData
kuma127
1
1.5k
趣味駆動学習のススメ〜野球の場合〜
kuma127
0
290
プロスペクトをデータで紹介
kuma127
2
2.5k
気軽に手に入る成績データで野球分析をしてみた
kuma127
0
2k
Python is simple and deep
kuma127
0
42
Other Decks in Programming
See All in Programming
[FlutterKaigi2024] Effective Form 〜Flutterによる複雑なフォーム開発の実践〜
chocoyama
1
3.9k
.NET 9アプリをCGIとして レンタルサーバーで動かす
mayuki
1
750
似たもの同士のPerlとPHP
uzulla
1
110
42 best practices for Symfony, a decade later
tucksaun
1
110
我々のデザインシステムは Chakra v3 にアップデートします
shunya078
2
2.9k
DevFest Tokyo 2025 - Flutter のアプリアーキテクチャ現在地点
wasabeef
4
530
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
150
As an Engineers, let's build the CRM system via LINE Official Account 2.0
clonn
1
640
Figma Dev Modeで変わる!Flutterの開発体験
watanave
0
3.7k
Serverless苦闘史
mosh_inc
0
140
Vapor Revolution
kazupon
2
2.5k
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
3.5k
Featured
See All Featured
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
1
87
Producing Creativity
orderedlist
PRO
341
39k
Practical Orchestrator
shlominoach
186
10k
Unsuck your backbone
ammeep
669
57k
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Adopting Sorbet at Scale
ufuk
73
9.1k
The Invisible Side of Design
smashingmag
298
50k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
Transcript
2019/9/17 DjangoͱJupyterͰ࢝ΊΔPyData ۽୩ TwitterIDɿ@kumappp27
͓લɺ୭Α ✤ ʮ۽୩ʯʢϋϯυϧωʔϜɿ͘·ͽʣͱ͍͍·͢ ✤ TwitterID:@kumappp27 ✤ ਓࡐܥͷձࣾͷWebΤϯδχΞ ✤ Pythonझຯ։ൃͰΑ͘ར༻ɺ େ͖ͳٿͷγεςϜΛ࡞
✤ #pyconjp ॳొஃͰ͢ʂυۓுͯ͠·͕͓ٓ͘͢͠ئ͍ ͠·͢ʂ
ຊͷ͓
DjangoͱJupyterͰ࢝ΊΔPyData
ൃදʹࢸ͖͔͚ͬͨͬᶃ ✤ ٿͷσʔλੳ͕ͨ͘͠Pythonελʔτ ✤ Jupyter NotebookΛѪ༻ ✤ Webͷཱࣝͭ͜ͱ͕໌ʢεΫϨΠϐϯάͱ͔
WebDataɺͲͬͪΓ͍ͨʂ
ൃදʹࢸ͖͔͚ͬͨͬᶄ ✤ ௐͯΈͨΒ DjangoͷϞσϧΛJupyter্Ͱ͑Δ ✤ ͔͠؆୯ɺͦͯ͠ສೳʂ ✤ ͜Εར༻ɾڞ༗͢Δ͔͠ͳ͍ʂ
ຊτʔΫͷత ✤ Django×Jupyterͳڥͷྑ͞Λ͑Δ͜ͱ ✤ ΦʔϧΠϯϫϯڥͰ࡞ۀֶशḿΔ͜ͱ
ΞδΣϯμ ✤ ͢͜ͱԼهΛ༧ఆ͍ͯ͠·͢ 1. DjangoͱJupyterͷ؆୯ͳհ 2. ਪ͍ͨ͠ཧ༝ 3. Django×JupyterͷΈ߹Θ͞ΔΠϝʔδ 4.
ڥߏஙํ๏ 5. ΦεεϝϥΠϒϥϦɾϓϥάΠϯҰྫ
DjangoͱJupyterͷ؆୯ͳհ
Djangoʹ͍ͭͯ ✤ DjangoʢδϟϯΰʣͱɺPythonͰ࣮͞ΕͨWeb ϑϨʔϜϫʔΫɻMVCσβΠϯύλʔϯʹ؇͔ʹै ͏ɻʢWikipediaΑΓʣ ✤ ڧྗͳORM͕͋Δ͜ͱͱɺϑϧελοΫͰ͋Δ͕ ࠾༻ཧ༝ɻ
Jupyterʹ͍ͭͯ ✤ ࠓճJupyterͷఏڙ͢ΔαʔϏεͷ ʮJupyter NotebookʯΛରɻ ✤ Jupyter Notebookɺίʔυͷଈ࣮࣌ߦՄࢹԽɺυ Ωϡϝϯτͷ࡞͕ߦ͑ΔWebΞϓϦέʔγϣϯɻ
Django×JupyterΛਪ͍ͨ͠ཧ༝
ਪ͍ͨ͠ཧ༝ 1. ϥΠϒϥϦΛ1ճΠϯετʔϧ͢Δ͚ͩ 2. DjangoٴͼJupyterͷϓϥάΠϯ͕๛ ˠΧόʔͰ͖Δൣғ͕͘ͳΔ
ͭ·Γ… ✤ खࠒʹDjango(Web)ͱJupyter(Data)ͷೋྲྀͳ ສೳڥ͕࡞ΕΔ
Django×JupyterͷΈ߹Θ͞ΔΠϝʔδ
DjangoͱJupyter͕Έ߹Θ͞ΔΠϝʔδ ✤ DjangoͷϞσϧΛJupyter্Ͱ͑Δʮ͚ͩʯ ✤ ओʹDjangoͷϞσϧΛར༻ͨ͠ڧྗͳORMͷԸܙΛ Jupyter্Ͱत͔Δܗ
ຊདྷJupyterͰDBʹΞΫηε͢Δ࣌ ✤ Jupyter্ͰɺDBʹͭͳ͙Πϝʔδ SQL
JupyterͰDBʹͭͳ͙࣌ͷ ✤ ඞཁͳॲཧ͕ଟ͍ - Jupyter্Ͱೝূઃఆ ɹଓॲཧ͕ඞཁ - جຊతʹSQLͰσʔλͷ ɹΓऔΓΛߦ͏ඞཁ͋Γ
Django×JupyterͰ ✤ DjangoΛհͯ͠ɺDBʹΞΫηε͢ΔΠϝʔδ ORM
DBར༻͕؆୯ʹ ✤ ࡞ۀͷ؆ུԽ - ଓઃఆɺ վΊͯΔඞཁͳ͠ - DjangoͷORM͕͑ΔͷͰɺ σʔλॲཧϥΫ
Έ߹ΘͤΔͱ͜Μͳ͜ͱ͕ग़དྷΔ
WebΞϓϦσʔλΛαΫοͱੳ ✤ WebΞϓϦͷσʔλΛɺͦͷ··Jupyter্Ͱར༻Ͱ͖Δ ✤ طଘڥʹେ͖ͳӨڹͳ͠ ✤ άϥϑදࣔεϥΠυԽ༰қ
εΫϦϓτΛརศతʹ࣮ߦͰ͖Δ ✤ WebΞϓϦ্ͷσʔλΛCSVʹՃ͢Δɺ ͱ͍ͬͨ࡞ۀஞҰڍಈΛ֬ೝ͠ͳ͕Β࣮ߦͰ͖Δ ✤ pandas͑ΔͷͰՃϥΫ ✤ ※વ࠷ॳςετڥͰ࣮ߦ͢Δɺͱ͍ͬͨ࠷ݶͷ ྀඞཁ
·ͱΊΔͱ… ✤ Web্ͷσʔλΛѻ͏ͨΊͷɺ ΠϯλʔϑΣʔεʹ Jupyter͕ͳͬͯ͘Ε͍ͯΔʂ
Django×Jupyterͷڥߏஙํ๏
Djangoͷڥߏங
Djangoͷڥߏங ✤ جຊతʹެࣜαΠτ௨Γͷߏஙํ๏ͰOK ✤ $ pip install django ✤ $
conda install django (Anacondaͷ߹) ✤ ※͍ͣΕͷ߹ԾڥΛཱͯͯΠϯετʔϧ͢Δ ͷ͕Φεεϝ
ΞϓϦͷ࡞ ✤ JupyterΛಋೖ͢ΔͨΊʹɺͱΓ͋͑ͣΞϓϦΛ࡞ $ django-admin startproject test_project $ cd test_project
$ python manage.py startapp test_app ✤ ʮtest_projectʯͱ͍͏ϓϩδΣΫτʹʮtest_appʯͱ ͍͏ΞϓϦΛ࡞ ✤ ※ৄ͘͠ެࣜυΩϡϝϯτࢀর (https://docs.djangoproject.com/ja/2.2/)
Jupyterͷಋೖ
ಋೖͱͬͯ؆୯ ✤ django-extensions ΛΠϯετʔϧ͢Δ͚ͩʂ ✤ pipͰΠϯετʔϧ͢Δ߹ $ pip install
django-extensions ✤ setting.pyͷINSTALLED_APPSʹҎԼΛՃ ‘django_extensions' ✤ ࢀߟɿhttps://github.com/django-extensions/django-extensions
JupyterͷىಈϥΫνϯ ✤ manage.pyͷ͋ΔϑΥϧμͰҎԼίϚϯυΛ࣮ߦ $ python manage.py shell_plus —notebook ✤ ىಈʹޭͨ͠Βɺදࣔ͞ΕͨURLΛϒϥβͰΞΫηε
✤ $ jupyter notebook Λ࣮ߦ͢Δͷͱ΄΅ಉ͡ʂ
DjangoͷϞσϧΛJupyterͰར༻͢Δ ✤ Jupyter্ͰϞσϧΛimport͢Δ͚ͩͰ ௨ৗ௨ΓϞσϧ͕ར༻Մೳʂ ✤ ෳࡶͳઃఆෆཁ ✤ ※ڥʹΑͬͯԼه4ߦͷ࣮ߦ͕ඞཁʹͳΓ·͢
ར༻Πϝʔδ ✤ DjangoͷORMͰऔಘͨ͠σʔλΛσʔλϑϨʔϜʹม
ʢ͓·͚ʣDockerͷઃఆͱҙ ✤ جຊతͳ࡞ΓํࠓճׂѪɺ ৄ͘͠DockerެࣜυΩϡϝϯτʹͯ ʢhttps://docs.docker.com/compose/django/ʣ ✤ Dockerʹͯઌड़ͷJupyterͷಋೖ·Ͱߦ͏ࡍɺ Jupyter༻ͷϙʔτͷ͚͕݀͋ඞਢͳͷͰҙ ΞΫηεͰ͖ͳ͘ͳΔʢܦݧஊʣ
ΦεεϝϥΠϒϥϦɾϓϥάΠϯҰྫ
ΦεεϝϥΠϒϥϦɾϓϥάΠϯͷҰྫ ✤ DjangoJupyterΛར༻͢Δ্Ͱ ཱͭϥΠϒϥϦϓϥάΠϯΛग़དྷΔݶΓհ ✤ ଞʹͨ͘͞Μ͋ΔͷͰɺڵຯΛ࣋ͬͨํௐͯΈ ͍ͯͩ͘͞
PyDataʹ͓͍ͯͷΦεεϝ ✤ Numpy ଟ࣍ݩྻΛαϙʔτ͢Δɺܭࢉ༻Ϟδϡʔϧ ػցֶशͷԋࢉʹศར ✤ pandas σʔλϑϨʔϜܗࣜͷྻΛఏڙ͢ΔϥΠϒϥϦ σʔλͷՄࢹԽɾՃʹ༏ΕΔ ✤
matplotlib PythonNumpyͷͨΊͷάϥϑඳըϥΠϒϥϦ ✤ ※ػցֶशपΓͷπʔϧࢲ͕ະܦݧͷͨΊ֎͍ͯ͠·͢…
Jupyterʹ͓͍ͯͷΦεεϝ ✤ nbextensions Jupyterʹ֦ுػೳΛಋೖग़དྷΔ LaTeXͷڥͩͬͨΓίʔυܗͩͬͨΓ ✤ RISE JupyterΛεϥΠυܗࣜʹมͰ͖Δ ඳըͨ͠άϥϑΛͦͷ··εϥΠυࢿྉʹ͢Δ࣌ͳͲʹΦεεϝ
Djangoʹ͓͍ͯͷΦεεϝ ✤ Django REST Framework Web API Λߏங͢ΔͨΊͷπʔϧ ໘ͳAPIͷઃఆ͕؆ུԽͰ͖Δ ✤
Django-filter ↑ͷDRFͱΈ߹ΘͤͯݕࡧػೳΛՃͰ͖Δ ✤ Django-pandas ϞσϧͷσʔλΛσʔλϑϨʔϜܗࣜʹมͰ͖Δ ͦͯ͠σʔλͷՄࢹԽɾՃʹར༻Ͱ͖Δ
࠷ޙʹ
Django×JupyterΛͬͯΈͯ ✤ WebͱσʔλํͷݟΛಘΕͨ - σʔλॲཧɺWeb։ൃಉ͡ڥͰͰ͖Δ - ΞτϓοτͷੵΈॏͶ͕ՄࢹԽ - Ϟνϕʔγϣϯͷҡ࣋ͱɺ࣮ӡ༻Λҙֶࣝͨ͠श ✤
͜Ε͔ΒPyDataΛ࢝ΊΔͳΒɺͥͻDjango×JupyterΛʂ
Ҏ্ɺ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ