4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Python / Pandasを利用して基本統計量を表示

Last updated at Posted at 2016-10-20

データ分析ライブラリモジュールであるpandasを利用して集計するための備忘録です。性能検証などの結果をいちいちExcelで読んで関数使って…よりは手っ取り早くて良いなと。

以下の記事を参考にしました。
Python pandas の算術演算 / 集約関数 / 統計関数まとめ

モジュールをインストール。

$ pip install pandas

サンプルファイルとしてタブ区切りで以下を準備。

sample.log
a	b	c	d	e
1	2	3	4	5
2	3	4	5	6
3	4	5	6	7
4	5	6	7	8

集計用スクリプトを作成。

qsum.py
#!/usr/bin/env python

import sys
import pandas as pd

dataFrame = pd.read_table(sys.argv[1])

print(dataFrame.describe())

実行結果。

$ ./qsum.py sample.log 
              a         b         c         d         e
count  4.000000  4.000000  4.000000  4.000000  4.000000
mean   2.500000  3.500000  4.500000  5.500000  6.500000
std    1.290994  1.290994  1.290994  1.290994  1.290994
min    1.000000  2.000000  3.000000  4.000000  5.000000
25%    1.750000  2.750000  3.750000  4.750000  5.750000
50%    2.500000  3.500000  4.500000  5.500000  6.500000
75%    3.250000  4.250000  5.250000  6.250000  7.250000
max    4.000000  5.000000  6.000000  7.000000  8.000000

動作確認環境:
Python 2.7.10
pandas-0.19.0

4
4
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
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?