728x90
DataFrame에 들어있는 데이터의 글자수 구하기
- apply 함수 안에, 내가 적용하고 싶은 함수의 이름만 써준다.
# 직원 이름이 몇글자인지, 이름 글자수를 구해서
# 새로운 컬럼 length 라는 컬럼에 저장하세요.
df
Employee ID Employee Name Salary [$/h] Years of Experience
0 111 Chanel 35 3
1 222 Steve 29 4
2 333 Mitch 38 9
3 444 Bird 20 1
# apply 함수 안에, 내가 적용하고 싶은 함수의 이름만 써준다.
df['length'] = df['Employee Name']. apply(len)
df
Employee ID Employee Name Salary [$/h] Years of Experience length
0 111 Chanel 35 3 6
1 222 Steve 29 4 5
2 333 Mitch 38 9 5
3 444 Bird 20 1 4
# 'Employee Name'의 이름의 문자 개수를 구해서
# 새로운 칼럼 length2에 저장하세요.
# 문자의 개수는 .str.len( )을 이용한다.
df['length2'] = df['Employee Name'].str.len()
df
Employee ID Employee Name Salary [$/h] Years of Experience length length2
0 111 Chanel 35 3 6 6
1 222 Steve 29 4 5 5
2 333 Mitch 38 9 5 5
3 444 Bird 20 1 4 4
728x90
'python > pandas' 카테고리의 다른 글
pandas - 조건을 만들어서 함수 정의하기 (0) | 2022.11.25 |
---|---|
pandas - DataFlame 안의 문자를 대문자, 소문자로 바꾸기 (0) | 2022.11.25 |
pandas - 카테고리컬 데이터( Categorical data )분석 및 가져오기 (0) | 2022.11.24 |
pandas - 문자열 컬럼에 describe( ) 함수 사용 (0) | 2022.11.24 |
pandas - 카테고리별 데이터( Categorical Data ) (0) | 2022.11.24 |