2014年12月6日土曜日

141206(2)

Pandas


sum, meanの使い方

>>> a = np.arange(24).reshape((6,4))
>>> a
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11],
       [12, 13, 14, 15],
       [16, 17, 18, 19],
       [20, 21, 22, 23]])
>>> df = DataFrame(a, index=['a','b','c','d','e','f'], columns=['one','two','thr
ee','four'])
>>> df
   one  two  three  four
a    0    1      2     3
b    4    5      6     7
c    8    9     10    11
d   12   13     14    15
e   16   17     18    19
f   20   21     22    23
>>> df.sum()
one      60
two      66
three    72
four     78
dtype: int64
>>> df.mean()
one      10
two      11
three    12
four     13
dtype: float64
>>> df.sum(axis=1)
a     6
b    22
c    38
d    54
e    70
f    86
dtype: int64
>>> df.mean(axis=1)
a     1.5
b     5.5
c     9.5
d    13.5
e    17.5
f    21.5
dtype: float64

0 件のコメント:

コメントを投稿

注: コメントを投稿できるのは、このブログのメンバーだけです。