LoginSignup
0
0

More than 3 years have passed since last update.

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

Posted at

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

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