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

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

by Jake VanderPlas, 菊池 彰
February 2024
Intermediate to advanced
576 pages
9h 17m
Japanese
O'Reilly Japan, Inc.
Content preview from Pythonデータサイエンスハンドブック 第2版 ―Jupyter、NumPy、pandas、Matplotlib、scikit-learnを使ったデータ分析、機械学習

13章pandasオブジェクトの基礎

非常に基本的なレベルにおいて、行と列が単純な整数インデクスではなくラベルで識別できるpandasオブジェクトは、NumPy構造化配列の拡張版と考えられます。この章で説明するように、pandasは基本的なデータ構造の上に多数の便利なツール、メソッド、機能を提供していますが、ほぼあらゆる場合で基礎的構造の理解が不可欠です。そこで高度な機能に踏み込む前に、3つの基本的なpandasデータ構造(SeriesDataFrameIndex)の基礎を学びます。

最初に、標準的な方法でNumPyとpandasをインポートします。

In [1]: import numpy as np
        import pandas as pd

13.1 Seriesオブジェクト

pandasのSeriesオブジェクトは、1次元のインデクス付きデータです。次のようにリストまたは配列から作成できます。

In [2]: data = pd.Series([0.25, 0.5, 0.75, 1.0])
        data
Out[2]: 0    0.25
        1    0.50
        2    0.75
        3    1.00
        dtype: float64

この出力からわかるように、Seriesは一連の値と一連のインデクスの組み合わせであり、それぞれvalues属性とindex属性でアクセスできます。valuesは、おなじみのNumPy配列です。

In [3]: data.values
Out[3]: array([0.25, 0.5 , 0.75, 1.  ])

indexは、pd.Index型の配列に似たオブジェクトです。これについては、後で詳しく説明します。

In [4]: data.index Out[4]: ...
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データサイエンスハンドブック ―Jupyter、NumPy、pandas、Matplotlib、scikit-learnを使ったデータ分析、機械学習

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

Jake VanderPlas, 菊池 彰
推薦システム実践入門 ―仕事で使える導入ガイド

推薦システム実践入門 ―仕事で使える導入ガイド

風間 正弘, 飯塚 洸二郎, 松村 優也
プロダクトマネージャーのしごと 第2版 ―1日目から使える実践ガイド

プロダクトマネージャーのしごと 第2版 ―1日目から使える実践ガイド

Matt LeMay, 永瀬 美穂, 吉羽 龍太郎, 原田 騎郎, 高橋 一貴

Publisher Resources

ISBN: 9784814400638Publisher Website