DjangoとJupyterで捗るPyData

685c9b622b253f8a53a8ef99b0453fb9?s=47 kuma127
August 08, 2019

 DjangoとJupyterで捗るPyData

8/8(木)の #stapy 発表資料です

685c9b622b253f8a53a8ef99b0453fb9?s=128

kuma127

August 08, 2019
Tweet

Transcript

  1. 2019/8/8 DjangoͱJupyterͰḿΔPyData ۽୩ ୓໵ TwitterIDɿ@kumappp27

  2. ͓લɺ୭Α ✤ ʮ۽୩ʯʢϋϯυϧωʔϜɿ͘·ͽʣͱ͍͍·͢ ✤ TwitterID:@kumappp27 ✤ ਓࡐܥͷձࣾͰWebΤϯδχΞ΍ͬͯ·͢ ✤ Python͸झຯ։ൃͰΑ͘ར༻ɺେ޷͖ͳ໺ٿͷγες Ϝ࡞ͬͯ·͢

    ✤ #stapy ॳొஃͰ͢ʂυۓுͯ͠·͕͓ٓ͘͢͠ئ͍͠ ·͢ʂ
  3. ࠓ೔࠷ॳʹݴ͓͖͍ͬͯͨ͜ͱ͕͋Γ·͢

  4. Ұࡢ೔ʢ6೔ʣ஀ੜ೔Ͱͨ͠Νʔʂ Happy birthday to me !

  5. ਖ਼௚͋·Γ… ਏ͍Ͱ͢ɺ20୅࠷ޙʢͷ஀ੜ೔ʣ͔ͩΒ

  6. ݸਓతͳωλ͸͓͖ͯ͞ɺຊ೔ͷ͓୊

  7. DjangoͱJupyterͰḿΔPyData

  8. ͓୊ʹ͍ͭͯᶃ ✤ ͦ΋ͦ΋PythonΛ࢝Ίͨͷ͸ɺσʔλ෼ੳ͕͖͔͚ͬ ✤ ͳͥσʔλ෼ੳ͔ͨͬͨ͠ͷ͔ͱ͍͏ͱɺ୯७ʹझຯ ͷ໺ٿͱབྷΊΒΕΔ෼໺͔ͩͬͨΒ ✤ ҰํͰۀ຿Ͱ͸Webܥͷ࡞ۀΛΑ͘΍ͬͯͯʢNot Pythonʣσʔλ෼ੳΛֶΜͰ͍͘͏ͪʹɺʮ݁ߏWeb ͷ஌ࣝ׆͔ͤΔͳʯͱࢥ͍ɺ͜ͷࢥ͍Λڞ༗ͨ͘͠ຊ

    ೔ͷςʔϚΛܾΊ·ͨ͠
  9. ͓୊ʹ͍ͭͯᶄ ✤ ͦͷதͰͳͥDjangoͱJupyterʹߜ͔ͬͨͱ͍͏ͱɺ ݩʑJupyterΛϝΠϯͰ࢖͍ͬͯͨͷͰ͕͢ 1. DjangoΛֶͼ࢝Ίͨஈ֊Jupyter֦ுػೳ͕͋Δͱ ஌ͬͨ͜ͱ 2. ͦΕʹΑͬͯDjangoͷϞσϧΛJupyter্Ͱ࢖͑Δɺ ͱ͍ͬͨ఺ʹՁ஋Λݟग़ͨ͜͠ͱ

    ✤ ͜ΕΒ͕ओͳཁҼͰ͢
  10. એ఻ ✤ ຊτʔΫͷBeginner޲͚ͷ࿩ʮDjangoͱJupyterͰ࢝ ΊΔPyDataʯ͕PyCon JP 2019ʹͯ15෼τʔΫͰ࠾୒ ͞Ε·ͨ͠ ✤ ΋͠Α͚Ε͹ௌ͖ʹ͖͍ͯͩ͘͞

  11. ͬ͘͟Γ֓ཁ ✤ ຊτʔΫ͸Django×Jupyterͳ؀ڥͷྑ͞Λ఻͑Δ͜ͱ Λ໨తͱ͍ͯ͠·͢ ✤ Jupyterͷ࠾༻໨త͸౰વσʔλ෼ੳͷͨΊͰ͕͢ɺ ΋ͪΖΜػցֶशʹ΋Ԡ༻Ͱ͖·͢ ✤ PyDataΛ͢Δʹ͋ͨͬͯɺσʔλϋϒͱͯ͠ Django×Jupyter؀ڥ͕σϑΝΫτελϯμʔυʹͳΔ

    Μ͡Όͳ͍͔ͳɺͱࢥͬͨΓࢥΘͳ͔ͬͨΓ
  12. ΞδΣϯμ ✤ ࿩͢͜ͱ͸ԼهΛ༧ఆ͍ͯ͠·͢ 1. Django×Jupyterͷಋೖ 2. ಋೖͷϝϦοτ 3. ׆༻ํ๏ʢҊʣ

  13. Django×Jupyterͷಋೖ

  14. ಋೖ͸ͱͬͯ΋؆୯ ✤ django-extensions ΛΠϯετʔϧ͢Δ͚ͩʂ ✤ pipͰΠϯετʔϧ͢Δ৔߹͸ 
 $ pip install

    django-extensions ✤ setting.pyͷINSTALLED_APPSʹҎԼΛ௥Ճ
 ‘django_extensions' ✤ ࢀߟɿhttps://github.com/django-extensions/django-extensions
  15. Jupyterͷىಈ΋ϥΫνϯ ✤ manage.pyͷ͋ΔϑΥϧμͰҎԼίϚϯυΛ࣮ߦ
 $ python manage.py shell_plus —notebook ✤ ىಈʹ੒ޭͨ͠Βɺදࣔ͞ΕͨURLΛϒϥ΢βͰΞΫηε

    ✤ $ jupyter notebook Λ࣮ߦ͢Δͷͱ΄΅ಉ͡ʂ
  16. DjangoͷϞσϧΛJupyterͰར༻͢Δ ✤ Jupyter্ͰϞσϧΛimport͢Δ͚ͩͰ௨ৗ௨ΓϞσ ϧ͕ར༻Ͱ͖·͢ʂ ✤ ෳࡶͳઃఆ౳͸ෆཁͰ͢ ※ͪ͜Β͸ҰྫͰ͢

  17. ಋೖͷϝϦοτ

  18. ಋೖͷϝϦοτ͸ʁ ✤ ࣮ࡍ͸DjangoͷϞσϧΛJupyter্Ͱ࢖͑Δʮ͚ͩʯ ͷػೳͰ͕͢ɺͦΕʹΑΔϝϦοτ͸͍͔ͭ͘ڍ͛Β Ε·͢ ✤ ओʹDjangoͷϞσϧΛར༻ͨ͠ڧྗͳORMͷԸܙΛ Jupyter্Ͱत͔Δܗ

  19. 1. ෼ੳ݁Ռ΍Ճ޻σʔλͷεϜʔζͳొ࿥ ✤ create()ΛJupyter্Ͱݺ΂ΔͷͰɺpandas౳Λ༻͍ͯ ࡞ΒΕͨσʔλΛͦͷ··DBʹొ࿥Ͱ͖·͢ ✤ SQLΛॻ͔ͳͯ͘΋σʔλ͕ొ࿥Մೳʂ

  20. 2. WebΞϓϦσʔλΛαΫοͱ෼ੳʹར༻Ͱ͖Δ ✤ ೔ࠒDjango੡ͷWebΞϓϦͰར༻͍ͯ͠ΔσʔλΛɺͦͷ··Jupyter ্Ͱར༻Ͱ͖·͢ ✤ pandasʹΑΔσʔλϑϨʔϜܗࣜͷදࣔͰ͋ͬͨΓɺmatplotlibΛ༻͍ ͨσʔλͷՄࢹԽͳͲ ✤ django-pandas

    ͱ͍͏ϥΠϒϥϦΛ࢖͑͹ɺϞσϧΛσʔλϑϨʔϜܗ ࣜʹม׵Ͱ͖·͢
  21. 3. εΫϦϓτΛརศతʹ࣮ߦͰ͖Δ ✤ Jupyterͱ͍͏͜ͱͰίʔυͷଈ࣮࣌ߦ͕ڧྗͳGUIʹΑͬ ͯͰ͖ΔͷͰɺWebΞϓϦ্ͷσʔλΛCSV౳ʹՃ޻͢ Δɺͱ͍ͬͨ࡞ۀ΋ஞҰڍಈΛ֬ೝ͠ͳ͕Β࣮ߦͰ͖·͢ ✤ ※ηΩϡϦςΟ౳ʹ͸഑ྀ͕ඞཁͰ͢

  22. ·ͱΊΔͱ… ✤ WebΞϓϦ্ͷσʔλΛѻ͏ͨΊͷΠϯλʔϑΣʔε ʹɺJupyter͕ͳͬͯ͘Ε͍ͯΔ ✤ Web×σʔλΛDjangoͰ͢ΔͳΒJupyterʂ

  23. ׆༻ํ๏ʢҊʣ

  24. طଘͷWebΞϓϦͰσʔλ෼ੳ΍ػցֶशΛ͍ͨ͠ ✤ ϥΠϒϥϦΛಋೖ͢Δ͚ͩͳͷͰ௿ίετͰಋೖͰ͖ ·͢ ✤ JupyterͷػೳΛ׆͔ͯ͠ɺσʔλ෼ੳ͚ͩͰͳ͘εϥ Πυ࡞ΓͳͲ΋Ͱ͖·͢ʢnbextensions΋࢖͑·͢ʣ

  25. Jupyter্ͰՃ޻ͨ͠σʔλΛWebAPIԽ͍ͨ͠ ✤ WebAPIͷ࡞੒͸Django REST Frameworkͱ͍͏ϥΠ ϒϥϦΛ࢖͑͹ʢൺֱతʣ༰қʹग़དྷ·͢ ✤ ϑϩϯτٕज़ͱ݁ͼ͚͍ͭͨ…ͳͲɺ༻్Λ͞Βʹ૿ ΍͢͜ͱ͕Ͱ͖·͢

  26. ࠷ޙʹ

  27. Ͳ͏Ͱ͔ͨ͠ʁ ✤ WebΞϓϦ΍σʔλʹؔ͢Δٕज़Λษڧ࢝͠Ίͨํʹ ݸਓతʹ͸ͥͻקΊ͍ͨͱࢥ͍ͬͯ·͢ ✤ ͢ͰʹͲ͔ͬͪ͸΍ͬͯΔΑʂͬͯਓ΋རศੑͷ޲্ ΍஌ݟͷձಘʹ׆͔ͤ·͢ʂ

  28. ͜ͷՆ͸… ✤ Webͱσʔλͷೋ౛ྲྀͰ։ൃͩʂ

  29. Ҏ্ɺ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ