Help us understand the problem. What is going on with this article?

python/pandas/dataframe/最もsimpleな行・列・index・columnの取得方法

More than 1 year has passed since last update.

DataFrame作成

▼ コード

df = pd.DataFrame([
    ['a0','b0','c0'],
    ['a1','b1','c1'],
    ['a2','b2','c2'],
    ['a3','b3','c3'],
], 
    columns=['a','b','c'],
    index=[0,1,2,3]
)
df

▼ 出力結果
image.png

行・列指定取得

▼ コード

# locを用いたケース
df.loc[[0,2],['a','c']]
# ilocを用いたケース
df.iloc[[0,2],[0,2]]

▼ 出力結果
image.png

index,columnの取得

indexの取得

▼ コード

df.index

▼ 出力結果
image.png

columnの取得

▼ コード

df.columns

▼ 出力結果
image.png

geshi
Ruby/Scala/Test/DDD
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away