bins=[0, 12, 19, 61, 100]
labels=['<12', 'Teen', 'Adult', 'Older']df['age_group'] = pd.cut(df['age'], bins, labels=labels)
All Pandas cut() you should know for transforming numerical data into categorical data
Numerical data is common in data analysis. Often you have numerical data that is continuous, or very large scales, or is highly skewed…...
towardsdatascience.com
df['age_group'] = pd.cut(
df['age'],
bins=[2, 12, 19, 61, 100],
include_lowest=True
)
'데이터 > Data Manipulation' 카테고리의 다른 글
[Pandas] Stratified sampling with pd.DataFrame.sample() (0) | 2022.10.13 |
---|---|
[6] Stratified K-fold 의 여러가지 방법 (0) | 2022.09.06 |
[4] Python list comprehension 써보기. (0) | 2022.05.29 |
[3] Pandas transform : lambda 대신 데이터프레임에 사용가능, 하지만 더 다양하게. (0) | 2022.05.29 |
[1] Pandas query : 한 번만 써보자! (0) | 2022.05.27 |
댓글