[pandas] ValueError: Bin labels must be one fewer than the number of bin edges

2023. 6. 26. 11:28Trouble shooting

pandas 로 data를 보고

나이를 나이대별로 그룹화 해서 보려던 도중

 

# 나이 구간 설정
bins = [0, 10, 20, 30, 40, 50, 60, 70, 80]

# 구간 라벨 설정
labels = ['0-9', '10-19', '20-29', '30-39', '40-49', '50-59', '60-69', '70-79', '80-89']

# 나이 구간 별로 새로운 컬럼 생성
data['AgeGroup'] = pd.cut(data['Age'], bins=bins, labels=labels)

 

ValueError: Bin labels must be one fewer than the number of bin edges

 

 

그냥 뜻 그대로 하나 더 적어야한다.

 

주의하자고 적어봄

728x90