1
0

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.

Pandas ピボットテーブル、pivot_table についてのメモ (作成中)

Posted at

2つの使用方法がある

  1. pandas.pivot_table()
  2. df.pivot_table()

この記事は1についてのみ書いています。

オプション

引数 役割 値の例
index=
values= 集計する列
margins= 集計行を付加するか否か Bool値
margins_name= 集計行の名前 "Total"
aggfunc= 集計の方法 初期値numpy.mean np.sum(ここでは関数に括弧不要)
dropna= 欠損値を除外するか否か Bool値(初期値True)
fill_value= 欠損値を穴埋めする際の代わりの値 0


# pivot
df_piv = pd.pivot_table(df_out ,
                        index=["製品品番",'品名',"品目","部品"] ,
                        values=["単価","総生産数",'お金'],
                        margins=True ,
                        margins_name="Total" ,
                        aggfunc=np.sum,
                        dropna=False,
                        fill_value = 0)
1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?