본문 바로가기
Python

[python]연속형 변수의 범주화 : Categorization

by Chandler.j 2021. 1. 8.
반응형

fig1. title

 

 

fig2. reference

참고 : https://rfriend.tistory.com/521

 


 

#1. pd.cut()을 이용해서 continuous -> categorical 변환.

 

#2. pd.cut(X, bins, labels)

  #2.1 X : dataframe, bins : bins=[미포함,포함], labels=['a']

 

  #2.2 source data

print(df_age_error)

fig3. source data

 

  #2.3 age categorization

age_cate = [18,29,39,49,59,69,80]
age_cate_name = ['20','30','40','50','60','70']

df_age_error['age_gp'] = pd.cut(df_age_error['age'], bins=age_cate, labels=age_cate_name)
print(df_age_error)

 

fig4. output of categorization

 


TOP

Designed by 티스토리