【python】DataFrameの統計量
DataFrameのデータの計算や統計の方法。
#各モジュールをインポートする import pandas as pd import numpy as np from pandas import Series, DataFrame #テスト用のDataFrameの作成 data = np.array([[1,2,np.nan], [np.nan, 3, 4, ]]) dframe = DataFrame(data, index=['A','B'], columns=['col1', 'col2', 'col3'])
いろいろな計算方法
#足し算 dframe1.sum() #出力結果 col1 1.0 col2 5.0 col3 4.0 dtype: float64 #行方向に足し算 dframe1.sum(axis=1) #出力結果 A 3.0 B 7.0 dtype: float64 #累計 dframe1.cumsum() #出力結果 col1 col2 col3 A 1.0 2.0 NaN B NaN 5.0 4.0
平均や分散などをまとめて表示する
dframe1.describe() #出力結果 col1 col2 col3 count 1.0 2.000000 1.0 #個数 mean 1.0 2.500000 4.0 #平均値 std NaN 0.707107 NaN #標準偏差 min 1.0 2.000000 4.0 #最小値 25% 1.0 2.250000 4.0 #25% 50% 1.0 2.500000 4.0 #50% 75% 1.0 2.750000 4.0 #75% max 1.0 3.000000 4.0 #最大値