Python DataFrameを作成するその④

続いてはDataFrameの限定した値を取得します

 

https://images.pyq.jp/repo/prod/pandas_structure_data_reference/pandas_structure_data_reference_14.jpg

df_loc_rowcol = df.loc['second', 'C']

print(df_loc_rowcol)

 

結果

"g"

 

 

df_loc_rowcol = df.loc[['second', 'fourth'], ['A', 'D']]
print(df_loc_rowcol)

 

結果

A D
second e h
fourth m p

 

☆ポイント☆

DataFrame.iloc[行番号, 列番号]でも絞り込めます。

 

以上、ちゃあ少佐でした。