PythonとTableauで福岡のオープンデータを可視化してみた。

A6605fa12ed2e613e4f0ff264532a99c?s=47 Taka710
December 27, 2018

 PythonとTableauで福岡のオープンデータを可視化してみた。

Pydata.Fukuoka#1のLT資料

A6605fa12ed2e613e4f0ff264532a99c?s=128

Taka710

December 27, 2018
Tweet

Transcript

  1. PythonͱTableauͰ ෱ԬͷΦʔϓϯσʔλ(ਓޱ)ΛՄࢹԽͯ͠Έͨ

  2. ࣗݾ঺հ • ⅓ɹܟതʢ͸·ɹ͔ͨͻΖʣ • ϓϩδΣΫτϚωʔδϟʔ΍ͬͯ·͢ɻ • PythonͱTableau͕େ޷͖Ͱ͢ʂ • PyCon Kyushu࣮ߦҕһ΋΍ͬͯ·͢ɻ

  3. ࠓճ΍Δ͜ͱ • ෱ԬݝͷΦʔϓϯσʔλαΠτ͔Βࢢ۠ொଜ ͷਓޱσʔλΛՄࢹԽ͢Δ

  4. ࠓճ࢖͏΋ͷ • Python 3.6 • xlrd ɿexcelϑΝΠϧΛಡΈॻ͖͢ΔPKG • gspread ɿgoogle

    spreadΛಡΈॻ͖͢ΔPKG • Tableau PublicʢDesktopʣ • ηϧϑBIπʔϧ • ແྉ൛ • Tableau PublicαΠτʹ͔͠อଘ͕Ͱ͖ͳ͍
  5. ߏ੒ 1. xlrdΛ࢖ͬͯΦʔϓϯσʔλΛऔΓࠐΈ 2. σʔλΛՃ޻ͯ͠ɺgoogle spreadʹॻ͖ࠐΈ 3. Tableau PublicͰσʔλΛಡΈࠐΜͰՄࢹԽ

  6. 1.excelϑΝΠϧΛಡΈࠐΈ • xlsxϑΥϧμʹΦʔϓϯσʔλΛ഑ஔ͠ɺ
 ϑΝΠϧΛಡΈࠐΉؔ਺Λ࡞੒ def get_xlsx_file_path(): main_path = os.path.dirname(os.path.abspath(__name__)) xlsx_path

    = os.path.join(main_path, ‘xlsx/*’) for xls_list in glob(xlsx_path): yield xls_list
  7. 2.excelϑΝΠϧΛಡΈࠐΈ • ਓޱͷΦʔϓϯσʔλͷ͏ͪෆཁͳσʔλΛ আ֎ͯ͠ಡΈࠐΈ • ࢢ΍܊͸ɺ۠΍ொΛར༻͢ΔͨΊεΩοϓ • for i in

    range(EXCEL_START_ROW, sheet.nrows - 1): if sheet.cell_value(i, 2) in DISTRICT: continue else: xls_data = [ file_date.strftime('%Y-%m-%d'), sheet.cell_value(i, 2), sheet.cell_value(i, 6), sheet.cell_value(i, 7), sheet.cell_value(i, 8), sheet.cell_value(i, 9) ] yield xls_data
  8. 3.google_spreadʹొ࿥ • γʔτ໊Λࢦఆͯ͠εϓϨουΛΦʔϓϯ • ྻຖʹεϓϨουΛߋ৽ google_sheet = gc.open(‘fukuoka_open_data').sheet1 ɾɾɾ for

    index, record in enumerate(get_xlsx_data(path)): cell_list = google_sheet.range(index + s_row, 1, index + s_row, len(record)) for cell, val in zip(cell_list, record): cell.value = val google_sheet.update_cells(cell_list) next_row = index + s_row + 1
  9. 4.Tableau PublicͰՄࢹԽ • πϦʔϚοϓΛ࡞ͬͯΈ·ͨ͠

  10. 4.Tableau PublicͰՄࢹԽ • ஍ਤͰՄࢹԽͯ͠Έ·ͨ͠ɻ

  11. 4.Tableau PublicͰՄࢹԽ • ࠷ऴతʹ͸ͪ͜Β https://public.tableau.com/profile/takahiro.hama8517#!/vizhome/ populationofFukuokaprefecture/fukuokapopulation GitHub: https://github.com/Taka710/fukuoka_open_data

  12. Tableau࠷ߴʂ

  13. ͓·͚ • ͔ͤͬ͘ͳͷͰGoogle DataPortal΋࢖ͬͯΈͨɻ
 ؆୯ʹՄࢹԽͰ͖Δͷ͸͍͍͔΋ɻ


  14. ͝੩ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ