LoginSignup
0
0

pandasのデータ構造について

Posted at

pandasのデータ構造について

慣れるべきふたつのデータ構造

シリーズ(Series)とデータフレーム(DataFrame)

1.Series

obj = pd.Series([4,7,-5,3])

0    4
1    7
2   -5
3    3
dtype: int64

値に関連づけられたインデックスというデータラベル配列が含まれる。
値にアクセスしたい場合は、values属性を使う。
obj.values

array([4, 7, -5, 3])

インデックス属性を使うと
obj.index

RangeIndex(start=0, stop=4, step=1)

のように返ってくる。そして、インデックスは指定できる。

obj2 = pd.Series([4,7,-5,3], index=['d', 'b', 'a', 'c'])

2.DataFrame

csvを読み込んだりするときに使う。

data = {'year':[2010, 2011, 2012, 2013],
        'month':['Jan', 'Fev', 'Mar', 'Apr']}
df = pd.DataFrame(data)
year month
0 2010 Jan
1 2011 Fev
2 2012 Mar
3 2013 Apr

こんな感じに配置される。

0
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
0
0