pandasのStyling機能で強化するJupyter実験レポート / PyConJP 2019

98df8bb11748bb59fef1aa1e474e8e02?s=47 komo_fr
September 16, 2019

pandasのStyling機能で強化するJupyter実験レポート / PyConJP 2019

98df8bb11748bb59fef1aa1e474e8e02?s=128

komo_fr

September 16, 2019
Tweet

Transcript

  1. QBOEBTͷ 4UZMJOHػೳͰڧԽ͢Δ +VQZUFS࣮ݧϨϙʔτ %BUF &WFOU1Z$PO+1 IUUQTQZDPOKQ  4QFBLFS5PNPLP'636,* !LPNP@GS

  2. @komo_fr 5PNPLP'636,*
 5XJUUFS!LPNP@GS w 1Z$PO+1΁ͷొஃ͸ճ໨ w લ৬1ZUIPOΛ࢖ͬͨσʔλ׆༻ͷ1P$΍ػցֶशҊ݅ʹैࣄ w ݱࡏϑϦʔ w

    ͨ·ʹ1ZUIPOຊͷϨϏϡʔ΋ͯ͠Δ w ʮ1ZUIPOʹΑΔ͋ͨΒ͍͠σʔλ෼ੳͷڭՊॻʯ w ᠳӭࣾࣉాֶ ⁋ਅޗ ླ໦͔ͨͷΓ ෱ౡਅଠ࿕ w ʮͰ͖Δ࢓ࣄ͕͸͔ͲΔ1ZUIPOࣗಈॲཧશ෦ೖΓɻʯ w ΠϯϓϨεຊ఩໵ த໺ਖ਼ً ஑ప Ԭా޾େ !2 8IPBN*
  3. @komo_fr w େలࣔϗʔϧͰ΍ͬͯΔΑ
 *κʔϯ  w 1&1ͷҾ༻ؔ܎ωοτϫʔΫ
 ͷ෼ੳ w &VSP1ZUIPO!εΠεͰ


    -5ͨ͠ωλ !3 -FU`T&YQMPSF1&1TXJUI/FUXPL9 1PTUFS4FTTJPO
  4. @komo_fr w ಺༰ w ศརͳ͕Β΋ॻ੶Ͱ͸͋·Γ঺հ͞Εͳ͍
 QBOEBTͷ4UZMJOHػೳʹ͍ͭͯɺ
 جຊతͳ࢖͍ํɾར༻ྫɾ஫ҙ఺ͳͲΛ঺հ͠·͢ w ର৅#FHJOOFS w

    ීஈɺ+VQZUFS/PUFCPPLͰ࣮ݧϨϙʔτΛॻ͘ػձ͕͋Δ
 QBOEBTϢʔβ w 4MJEF w IUUQTTQFBLFSEFDLDPNLPNPGSQZDPOKQ !4 ࠓ೔࿩͢͜ͱ
  5. @komo_fr w 4UZMJOHػೳͱ͸ w 4UZMJOHػೳΛ࢖͏Ϟνϕʔγϣϯ w جຊͷ࢖͍ํ w 4UZMFSͷศརͳػೳ w

    &YDFM΁ͷΤΫεϙʔτ w 4UZMJOHػೳ࢖༻࣌ͷ஫ҙ఺ !5 "HFOEB
  6. @komo_fr w 4UZMJOHػೳͱ͸ w 4UZMJOHػೳΛ࢖͏Ϟνϕʔγϣϯ w جຊͷ࢖͍ํ w 4UZMFSͷศརͳػೳ w

    &YDFM΁ͷΤΫεϙʔτ w 4UZMJOHػೳ࢖༻࣌ͷ஫ҙ఺ !6 "HFOEB
  7. @komo_fr w QBOEBTͷ4FSJFT%BUB'SBNFʹ৚݅෇͖ॻࣜΛద༻͢Δػೳ w FH ෛͷ஋͸੺ࣈʹ͢Δɺ֤ߦͷ࠷େ஋ͷഎܠ৭Λม͑Δ w ελΠϧઃఆʹ͸$44Λ࢖͏ w ͳͯ͘΋ੜ͖͍͚ͯΔ͕ɺ࢖͑Δͱศརʢओ؍ʣ

    !7 4UZMJOHػೳ 4UZMJOHcQBOEBT6TFS(VJEF IUUQTQBOEBTQZEBUBPSHQBOEBTEPDTTUBCMFVTFS@HVJEFTUZMFIUNM
  8. @komo_fr !8 ྫʣΧςΰϦຖʹ৭Λมߋ๮άϥϑΛදࣔ w 1&1 1ZUIPO&OIBODFNFOU1SPQPTBMT ͷඃҾ༻਺ϥϯΩϯά ΧςΰϦຖʹ৭Λมߋ

  9. @komo_fr !9 ྫʣΧςΰϦຖʹ৭Λมߋ๮άϥϑΛදࣔ w 1&1 1ZUIPO&OIBODFNFOU1SPQPTBMT ͷඃҾ༻਺ϥϯΩϯά ਺஋ܕͷྻͷഎܠʹ ๮άϥϑΛදࣔ

  10. @komo_fr w 4UZMJOHػೳͱ͸ w 4UZMJOHػೳΛ࢖͏Ϟνϕʔγϣϯ w جຊͷ࢖͍ํ w ϏϧτΠϯؔ਺ w

    &YDFM΁ͷΤΫεϙʔτ w 4UZMJOHػೳ࢖༻࣌ͷ஫ҙ఺ !10 "HFOEB
  11. @komo_fr w σʔλΛѻ͏தͰɺ+VQZUFS্Ͱ%BUB'SBNFͷத਎Λ֬ೝ͢Δ w ͦͷதͰɺ%BUB'SBNFͷҰ෦ͷηϧΛڧௐͯ͠ද͍ࣔͨ͠ͱ͖͕͋Δ w FY ߦຖͷ࠷େ஋ɺܽଛ஋ʜʜ w γνϡΤʔγϣϯ

    w ࣗ෼ͰσʔλΛ୳ࡧͯ͠ࢼߦࡨޡ͍ͯ͠Δͱ͖ w άϥϑͷܗʹཁ໿ͤͣʹɺςʔϒϧͷ··၆ᛌ͍ͨ͠ͱ͖ w ࣮ݧޙʹɺଞऀʹ޲͚ͨใࠂࢿྉΛ࡞Δͱ͖ w ʮදͷ͜͜ͷ෦෼͕ϙΠϯτͰ͢ΑʯͱҰ෦Λ͍ࣔͨ͠ͱ͖ !11 4UZMJOHػೳΛ࢖͏Ϟνϕʔγϣϯ
  12. @komo_fr w ྫʮϥϕϧຖͷڭࢣσʔλ਺Λ
 +VQZUFS্Ͱ֬ೝ͢Δͱ͖ʹɺ
 ϥϕϧຖͷภΓ΍ɺ
 ۃ୺ʹσʔλ਺͕গͳ͍ϥϕϧΛ
 ͬ͘͞ͱΘ͔Γ΍͘͢ڧௐ͍ͨ͠ʯ w ˠηϧͷഎܠʹ๮άϥϑΛදࣔ
 ະຬͷσʔλΛ੺ࣈͰڧௐ

    !12 ྫ ڭࢣσʔλ਺ͷ֬ೝ
  13. @komo_fr w QBOEBT+VQZUFS/PUFCPPL͔Βಈ͔ͳ͍͍ͯ͘ w ใࠂࢿྉͷ৔߹ ͪΐͬͱͨ͠૷০ͷͨΊʹ
 ύϫϙʹҠಈͨ͘͠ͳ͍ w ίʔυͰهड़͍ͯ͠Δ࠶ར༻ࣗಈԽ͠΍͍͢ w

    +VQZUFS/PUFCPPLͰϨϙʔτͷϑΥʔϚοτΛ࡞ͬͯ
 ಉ༷͡ͳ࣮ݧΛԿ౓΋܁ΓฦͤΔ w Ұ౓࡞ͬͨελΠϧͷઃఆʢελΠϧؔ਺ʣΛɺ
 ผͷςʔϚͷ࣮ݧͰ΋࢖͍ճͤΔ !13 Կ͕خ͍͠ͷ͔
  14. @komo_fr w 4UZMJOHػೳͱ͸ w 4UZMJOHػೳΛ࢖͏Ϟνϕʔγϣϯ w جຊͷ࢖͍ํ w 4UZMFSͷศརͳػೳ w

    &YDFM΁ͷΤΫεϙʔτ w 4UZMJOHػೳ࢖༻࣌ͷ஫ҙ఺ !14 "HFOEB
  15. @komo_fr  $44จࣈྻΛฦ͢ελΠϧؔ਺Λఆٛ͢Δ  BQQMZNBQ·ͨ͸BQQMZΛ࢖ͬͯɺελΠϧؔ਺Λద༻͢Δ ͨͩ͠ద༻͍ͨ͠୯ҐʢཁૉPSߦྻσʔλϑϨʔϜʣʹΑͬͯ
 ελΠϧؔ਺ͷҾ਺ɾ໭Γ஋΍ɺ࢖͏ϝιου͕มΘΔ ελΠϧద༻ͷجຊ "SBLJ #BCB

    $IPV ࠃ ޠ    ਺ ֶ    ཧ Պ    ࣾ ձ    "SBLJ #BCB $IPV ࠃ ޠ    ਺ ֶ    ཧ Պ    ࣾ ձ    "SBLJ #BCB $IPV ࠃ ޠ    ਺ ֶ    ཧ Պ    ࣾ ձ    BQQMZNBQ BQQMZ BYJT BYJT !15
  16. @komo_fr !16 ྫ੺఺ͷ੒੷Λ੺ࣈʹ͢Δ ੜె Պ ໨

  17. @komo_fr !17 ྫ੺఺ͷ੒੷Λ੺ࣈʹ͢Δ ੺఺ʢ఺ະຬʣΛ੺ࣈͰɺ ͦΕҎ֎ΛࠇࣈͰද͍ࣔͨ͠ ੜె Պ ໨

  18. @komo_fr ྫ੺఺ͷ੒੷Λ੺ࣈʹ͢Δ !18  ηϧͷ஋ʹԠͯ͡ $44Λฦ͢ ελΠϧؔ਺Λ ༻ҙ  

    TUZMFBQQMZNBQϝιουʹ ελΠϧؔ਺Λ౉ͯ͠ ֤ཁૉʹద༻͢Δ
  19. @komo_fr ྫOVMMͷηϧͷจࣈ৭ɾഎܠ৭Λม͑Δ !19

  20. @komo_fr w QBOEBTJPGPSNBUTTUZMF4UZMFSΫϥε w )5.-ͱ$44Λ࢖ͬͯ
 %BUB'SBNF΍4FSJFTͷελΠϧΛઃఆ͢ΔΫϥε w BQQMZNBQ BQQMZͳͲελΠϧΛద༻͢ΔϝιουΛ࣋ͭ w

    4UZMFSΦϒδΣΫτΛ+VQZUFS্Ͱ࣮ߦ͢Δͱɺ
 @SFQS@IUNM@ϝιου͕ࣗಈͰݺ͹ΕͯϨϯμϦϯά͞ΕΔ w %BUB'SBNFTUZMFϓϩύςΟ w 4UZMFSΦϒδΣΫτΛฦ͢ !20 4UZMFSΫϥε%BUB'SBNFTUZMFϓϩύςΟ
  21. @komo_fr %BUB'SBNFTUZMFͷத਎ ελΠϧແͷঢ়ଶ !21 $44ͷઃఆ ʢ·ͩத਎͕ͳ͍ʣ SFOEFS Λ࢖͏ͱத਎Λ֬ೝͰ͖Δ

  22. @komo_fr BQQMZNBQΛద༻ͨ͠த਎ !22 SPX@DPM͸ࠇจࣈ SPX@DPM͸੺จࣈ

  23. @komo_fr w BQQMZNBQ ͸4UZMFSΦϒδΣΫτΛฦ͢ w ͦͷ4UZMFSΦϒδΣΫτ΋ʢ౰વ͕ͩʣBQQMZNBQ Λ࣋ͭ !23 ਺चܨ͗Ͱෳ਺ͷελΠϧؔ਺Λద༻Ͱ͖Δ

  24. @komo_fr !24 ࠷ޙʹద༻ͨ͠$44͕༏ઌ͞ΕΔ ˡpMM@OBO@ͷઃఆ ˡpMM@OBO@ͷઃఆ SFOEFS ϝιουͷ݁Ռ

  25. @komo_fr w ʮ஋͕఺ະຬ͔Ͳ͏͔ʯʮηϧ͕OVMM͕Ͳ͏͔ʯͳͲ w ֤ཁૉͷ஋ΛݸผʹݟΕ͹Θ͔Δ w BQQMZNBQ Λ࢖͏ w ʮશͯͷߦͰҰ൪େ͖͍஋ͷഎܠ৭Λม͑ΔʯʮલͷߦΑΓେ͖

    ͍஋ͩͬͨΒจࣈ৭Λม͑ΔʯͳͲ w ୯ମͷཁૉ͚ͩͰ͸ͳ͘ɺ
 ଞͷཁૉ΋ؚΊͯ൑அ͢Δඞཁ͕͋Δ w BQQMZ Λ࢖͏ !25 ߦશମɾྻશମΛݟΔඞཁ͕͋Δ৔߹
  26. @komo_fr !26 ྫɿ֤ڭՊͰ࠷΋ಘ఺͕ߴ͔ͬͨਓΛڧௐ  4FSJFTܕΛड͚औΔ  $44จࣈྻͷϦετΛฦ͢  BYJTͰద༻ํ޲Λࢦఆ BYJT/POFͷ৔߹͸ɺ


    4FSJFTͰ͸ͳ͘
 %BUB'SBNF୯ҐͰݟΔ
  27. @komo_fr w 4UZMJOHػೳͱ͸ w 4UZMJOHػೳΛ࢖͏Ϟνϕʔγϣϯ w جຊͷ࢖͍ํ w 4UZMFSͷศརͳػೳ w

    &YDFM΁ͷΤΫεϙʔτ w 4UZMJOHػೳ࢖༻࣌ͷ஫ҙ఺ !27 "HFOEB
  28. @komo_fr w IJHIMJHIU@NBY IJHIMJHIU@NJO  w ࠷େ஋ɺ࠷খ஋ͷഎܠ৭Λม͑ΔʢσϑΥϧτͰ͸ԫ৭ʣ w IJHIMJHIU@OVMM 

    w OVMMͷηϧͷഎܠ৭Λม͑ΔʢσϑΥϧτͰ͸੺ʣ w CBS  w ηϧͷഎܠʹ๮άϥϑΛඳ͘ w ݸਓతʹ͸Ұ൪ଟ༻͢Δ w CBDLHSPVOE@HSBEJFOU  w ஋ʹԠͯ͡എܠΛάϥσʔγϣϯ͢Δ !28 Α͘࢖͏ελΠϧؔ਺͸͋Β͔͡Ί༻ҙ͞Ε͍ͯΔ
  29. @komo_fr !29 CBS എܠʹ๮άϥϑΛඳը ˡ࠷େ஋෯ ˡ࠷খ஋෯

  30. @komo_fr !30 CBS എܠʹ๮άϥϑΛඳը ஍఺Λதԝʹἧ͑Δ } } ਖ਼ͷ஋ ෛͷ஋

  31. @komo_fr !31 CBS എܠʹ๮άϥϑΛඳը ๮άϥϑͷ৭Λมߋ

  32. @komo_fr w TFU@DBQUJPO  w ςʔϒϧʹΩϟϓγϣϯΛ͚ͭΔ w TFU@QSFDJTJPO  w

    දࣔ͢Δࡍͷ༗ޮܻ਺Λࢦఆ w σʔλͦͷ΋ͷʹ͸Өڹ͸ͳ͍ w TFU@QSPQFSUJFT  w ελΠϧؔ਺Λ࢖Θͣɺ௚઀$44Λࢦఆ w σʔλͷ৚݅ʹΑΒͣɺ
 ҰׅͰಉ͡ελΠϧΛద༻͍ͨ͠ͱ͖ʹศར !32 ͦͷଞͷศརͳػೳ ˣΩϟϓγϣϯ
  33. @komo_fr w 4UZMJOHػೳͱ͸ w 4UZMJOHػೳΛ࢖͏Ϟνϕʔγϣϯ w جຊͷ࢖͍ํ w 4UZMFSͷศརͳػೳ w

    &YDFM΁ͷΤΫεϙʔτ w 4UZMJOHػೳ࢖༻࣌ͷ஫ҙ఺ !33 "HFOEB
  34. @komo_fr w ʮ+VQZUFSͳΜͯ஌ΒΜ͔Β&YDFMͰ͘Εʯ w 4UZMFSΫϥεͷUP@FYDFM ϝιου w PQFOQZYMΛผ్Πϯετʔϧ͢Δඞཁ༗ w IUUQTPQFOQZYMSFBEUIFEPDTJPFOTUBCMF

    JOEFYIUNM !34 &YDFMϑΝΠϧ΁ͷΤΫεϙʔτ
  35. @komo_fr w ελΠϧΛ൓өͨ͠&YDFMϑΝΠϧ͕ΤΫεϙʔτ͞ΕΔ w ৚݅ࣜࣗମ͕ग़ྗ͞ΕΔΘ͚Ͱ͸ͳ͍ w &YDFM্ͷ஋Λม͑ͯ΋ελΠϧ͸ߋ৽͞Εͳ͍ !35 UP@FYDFM ϝιου

    +VQZUFS &YDFM
  36. @komo_fr w ʢ౰વ͕ͩʣ&YDFMͰදݱͰ͖ͳ͍΋ͷ͸Ͱ͖ͳ͍ !36 શ͕ͯม׵Ͱ͖ΔΘ͚Ͱ͸ͳ͍ +VQZUFS &YDFM

  37. @komo_fr w 4UZMJOHػೳͱ͸ w 4UZMJOHػೳΛ࢖͏Ϟνϕʔγϣϯ w جຊͷ࢖͍ํ w 4UZMFSͷศརͳػೳ w

    &YDFM΁ͷΤΫεϙʔτ w 4UZMJOHػೳ࢖༻࣌ͷ஫ҙ఺ !37 "HFOEB
  38. @komo_fr ͋͘·Ͱ1SPWJTJPOBM (JU)VCʹVQ͢ΔͱελΠϧ͕ফ͑Δ w ผͷαʔϏεʢOCWJFXFSͳͲʣΛ࢖͓͏  มͳ$44Λ౰ͯͯ΋ྫ֎͸ൃੜ͠ͳ͍ʢͷͰؾ෇͖ʹ͍͘ʣ w Կ͔มͩͳʁͱࢥͬͨΒSFOEFS Ͱ֬ೝ͠Α͏

    w ڽͬͨ͜ͱΛ΍Γ͍ͨͳΒ
 ૉ௚ʹଞͷՄࢹԽϥΠϒϥϦΛ࢖͏ํ͕ྑ͍͔΋ !38 4UZMJOH࢖༻࣌ͷ஫ҙ఺
  39. @komo_fr w 4UZMJOHc6TFS(VJEF w ͱ͸͍͑ɺॳճϦϦʔεͷ͔Βطʹ໿೥ܦա w ϦϦʔε w (JUͷίϛοτϩάΛݟͨͱ͜Ζɺසൟʹػೳ௥Ճ͕͋ΔΘ͚Ͱ ͸ͳ͍͕ɺυΩϡϝϯτ΍ίʔυ੔ܗπʔϧͷద༻ͳͲ


    ϝϯς͸͞Ε͍ͯΔΈ͍ͨʁ !39 ͋͘·Ͱ1SPWJTJPOBM 1SPWJTJPOBM5IJTJTBOFXGFBUVSFBOETUJMMVOEFS EFWFMPQNFOU8F`MMCFBEEJOHGFBUVSFTBOEQPTTJCMZNBLJOH CSFBLJOHDIBOHFTJOGVUVSFSFMFBTFT8F`EMPWFUPIFBSZPVS GFFECBDL https://pandas.pydata.org/pandas-docs/stable/user_guide/style.html
  40. @komo_fr w QBOEBTʹݶΒͣʣ(JU)VC্ͷJQZOCϑΝΠϧͰ͸$44͸൓ө͞Εͳ͍ w ελΠϧΛద༻ͯ͠΋࣮ݧϨϙʔτΛ(JU)VCͰڞ༗͠Α͏ͱͯ͠΋ PS[ !40 (JU)VCͰڞ༗͢Δͱ$44͕൓ө͞Εͳ͍ ϩʔΧϧͷ+VQZUFS্ͷදࣔ (JU)VC্ͷදࣔ

  41. @komo_fr w OCWJFXFS IUUQTOCWJFXFSKVQZUFSPSH  w (JU)VC্ͷJQZOCϑΝΠϧͷ63-Λࢦఆ͢Δͱɺ
 +VQZUFS/PUFCPPLͷ಺༰͕)5.-ͱͯ͠දࣔ͞ΕΔ !41 ୅ସҊɿผͷ+VQZUFSϑΝΠϧͷϏϡʔΞΛ࢖͏

  42. @komo_fr !42 มͳ$44Λ౰ͯͯ΋ྫ֎͸ൃੜ͠ͳ͍ w Կ͔มͩͳʁͱࢥͬͨΒSFOEFS Λ࢖ͬͯ$44Λ֬ೝ͠Α͏ w ڽͬͨ͜ͱΛ΍Γ͍ͨͳΒ
 ૉ௚ʹଞͷՄࢹԽϥΠϒϥϦΛ࢖͏ํ͕ྑ͍͔΋

  43. ·ͱΊ !43

  44. @komo_fr w QBOEBTͷ4UZMJOHػೳʹ͍ͭͯ঺հ͠·ͨ͠ w ͳͯ͘΋ੜ͖͍͚ͯΔ͕ɺ࢖͑ΔͱԿ͔ͱศར w +VQZUFSͰϨϙʔτΛॻ͜͏ͱ͢Δͱ͖ʹॏๅ͢Δ w ελΠϧؔ਺Λࣗ࡞Ͱ͖Δ w

    ศརͳػೳ͸͋Β͔͡Ί༻ҙ͞Ε͍ͯΔ w ΑΓৄ͘͠஌Γ͍ͨਓ͸ w 6TFS(VJEF w IUUQTQBOEBTQZEBUBPSHQBOEBTEPDTTUBCMFVTFS@HVJEFTUZMFIUNM w "1*3FGFSFODF w IUUQTQBOEBTQZEBUBPSHQBOEBTEPDTTUBCMFSFGFSFODFTUZMFIUNM !44 ·ͱΊ
  45. @komo_fr w 4MJEF w IUUQTTQFBLFSEFDLDPNLPNPGSQZDPOKQ w (JU)VC w IUUQTHJUIVCDPNLPNPGS 1Z$PO+1@QBOEBT@TUZMJOH

    w OCWJFXFS w IUUQTOCWJFXFSKVQZUFSPSHHJUIVCLPNPGS 1Z$PO+1@QBOEBT@TUZMJOHCMPCNBTUFSOPUFCPPLT TUZMJOHJQZOC !45 63-
  46. (PPEZPVSQBOEBTMJGF