Skip to Content
Pythonデータサイエンスハンドブック ―Jupyter、NumPy、pandas、Matplotlib、scikit-learnを使ったデータ分析、機械学習
book

Pythonデータサイエンスハンドブック ―Jupyter、NumPy、pandas、Matplotlib、scikit-learnを使ったデータ分析、機械学習

by Jake VanderPlas, 菊池 彰
May 2018
Intermediate to advanced
556 pages
13h 21m
Japanese
O'Reilly Japan, Inc.
Content preview from Pythonデータサイエンスハンドブック ―Jupyter、NumPy、pandas、Matplotlib、scikit-learnを使ったデータ分析、機械学習
172
3
章 
pandas
を使ったデータ操作
ら生存率の平均を算出した上で、隠れた多次元性を明らかにするために
unstack()
で階層型インデ
クスを作ります。
In[4]: titanic.groupby(['sex', 'class'])['survived'].aggregate('mean').unstack()
Out[4]: class First Second Third
sex
female 0.968085 0.921053 0.500000
male 0.368852 0.157407 0.135447
これにより、性別と等級の両方がどのように生存に影響を与えたかがわかりますが、コードは複
雑になり始めています。このパイプラインの各ステップは、先に説明した手段を使う上で妥当なも
ではありますが、長いコード列は特に読みやすいわけでも、使いやすいわけでもありません。こ
2
次元の
GroupBy
は非常に一般的であるため、この種の多次元集約を簡潔に処理する便利な関数
pivot_table
pandas
は提供しているのです。
3.10.3
 ピボットテーブルの文法
DataFrame
pivot_table
メソッドを使用して、先の例と同じ操作を行います。
In[5]: titanic.pivot_table('survived', index='sex', columns='class')
Out[5]: class First Second Third
sex
female 0.968085 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Pythonデータサイエンスハンドブック 第2版 ―Jupyter、NumPy、pandas、Matplotlib、scikit-learnを使ったデータ分析、機械学習

Pythonデータサイエンスハンドブック 第2版 ―Jupyter、NumPy、pandas、Matplotlib、scikit-learnを使ったデータ分析、機械学習

Jake VanderPlas, 菊池 彰
初めてのGraphQL ―Webサービスを作って学ぶ新世代API

初めてのGraphQL ―Webサービスを作って学ぶ新世代API

Eve Porcello, Alex Banks, 尾崎 沙耶, あんどうやすし

Publisher Resources

ISBN: 9784873118413Other