Post

[Python] df 행|열 레이블 :: df.indedx | df.colunmns

Reference Pandas In Action
1
2
3
4
5
6
7
import pandas as pd

nba = pd.read_csv(
    './Data/nba.csv',
    parse_dates = ['Birthday']  # 'Birthday'의 데이터 유형을 날짜/시간(datetime)으로 강제 변환
)
nba
 NameTeamPositionBirthdaySalary
0Shake MiltonPhiladelphia 76ersSG1996-09-261445697
1Christian WoodDetroit PistonsPF1995-09-271645357
2PJ WashingtonCharlotte HornetsPF1998-08-233831840
3Derrick RoseDetroit PistonsPG1988-10-047317074
4Marial ShayokPhiladelphia 76ersG1995-07-2679568
445Austin RiversHouston RocketsPG1992-08-012174310
446Harry GilesSacramento KingsPF1998-04-222578800
447Robin LopezMilwaukee BucksC1988-04-014767000
448Collin SextonCleveland CavaliersPG1999-01-044764960
449Ricky RubioPhoenix SunsPG1990-10-2116200000

450 rows × 5 columns

1. df 인덱스(행 레이블) :: df.index

1
df.index
  • DataFrame의 Index 확인
1
nba.index   # nba의 인덱스 값
1
RangeIndex(start=0, stop=450, step=1)

2. df columns(열 레이블) :: df.columns

1
df.columns
  • DataFrame의 column들의 이름 확인
1
nba.columns # nba의 columns 값
1
Index(['Name', 'Team', 'Position', 'Birthday', 'Salary'], dtype='object')
This post is licensed under CC BY 4.0 by the author.