0
1

More than 1 year has passed since last update.

40代おっさんPythonを勉強する(データ解析,Pandas編①)

Posted at

本記事について

この記事はプログラミング初学者の私が学んでいく中でわからない単語や概要を分かりやすくまとめたものです。
もし不正などありましたらコメントにてお知らせいただければ幸いです。

Pandas

  • データ分析を支援するPythonのライブラリ
  • 元々金融データの操作のために設計された
  • スプレッドシートやリレーショナルデータベースの処理ができる
  • DataFrameという基本データ構造を定義されている
  • 科学データだけではなく、ビジネスデータの処理でも単純化している
  • ホームページ https://pandas.pydata.org
  • ドキュメンテーション https://pandas.pydata.org/pandas-docs/stable/

データの可視化

  • データをグラフとして見せる
  • 数字だけよりわかりやすい
  • Pandasで簡単なグラフをすぐに作成できる
  • Matplotlibを並行で使うと綺麗なグラフになる

Matplotlib

  • プロットライブラリであり、データ可視化に役に立つ
  • たくさんの統計グラフや実験結果を表示することができる
  • 折れ線、棒グラフ、円グラフ、ヒストグラム、パワースペクトル、散布図、など
  • Matplotlibの参考はhttps://matplotlib.org

日本語のフォントを設定

  • フォントがない文字ではグラフに表示できないため
  • 英文字以外のフォントを設定する必要
#  自分の環境のフォントを調べる
#  必要なフォントを探し出す
from matplotlib import font_manager

fonts = set([f.name for f in font_manager.fontManager.ttflist])
# print(fonts)

for f in fonts:
    if 'Mincho' in f or 'Gothic' in f or 'Meiryo' in f or 'Hiragino' in f:
        print(f)
  • エラーでNo module named 'matplotlib'が出ましたその時はpip3 install matplotlibmatplotlibをインストールする。
#  日本語のフォントを設定する
import matplotlib.pyplot as plt

# MacOSで使えるフォント
# Hiragino Maru Gothic Pro
# Hiragino Mincho ProN
# Hiragino Sans GB
# Hiragino Sans
# plt.rcParams["font.family"] = "Hiragino Maru Gothic Pro" # Macの方はこちら

# Windowsで使えるフォント
# MS Mincho
# MS Gothic
# Meiryo
plt.rcParams['font.family'] = "MS Gothic" # 自分はWindowsを選ぶ
# このグラフがちゃんと表示できたらOK
labels = ['<42', '43~48', '49~59', '60~64', '>65', '不明']
sizes = [36.7, 31.5, 19.7, 6.4, 5.2, 0.5]
plt.pie(sizes, labels=labels, autopct='%.1f%%')
plt.title('2017年 20~29歳の若者の週間就業時間別割合')
plt.legend(title='時間', loc='center right', bbox_to_anchor=(1.5, 0.5))
plt.show()

参考

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1