# リスト3.3.1:Seriesの作成
import pandas as pd
ser = pd.Series([1, 2, 3], index=["a", "b", "c"])
ser
a 1 b 2 c 3 dtype: int64
# リスト3.3.3:indexを省略したSeriesの作成
pd.Series([1, 2, 3])
0 1 1 2 2 3 dtype: int64
# リスト3.3.7:ラベルによる指定
ser.loc["b"]
2
# リスト3.3.9:[]による指定
ser["b"]
2
# リスト3.3.10:スライスを使用した指定
ser.loc["b":"c"]
b 2 c 3 dtype: int64
# リスト3.3.12:リストを使用したラベル指定
ser.loc[["a", "c"]]
a 1 c 3 dtype: int64
# リスト3.3.14:ilocによる指定
ser.iloc[1]
2
# リスト3.3.16:位置をスライスで指定
ser.iloc[1:3]
b 2 c 3 dtype: int64
# リスト3.3.18:真偽値による指定
ser.loc[[True, False, True]]
a 1 c 3 dtype: int64
# リスト3.3.20:Seriesに対する比較演算
ser != 2
a True b False c True dtype: bool
# リスト3.3.22:比較演算を利用したデータの抽出
ser.loc[ser != 2]
a 1 c 3 dtype: int64