여러 가지 이야기/에러 모음
ValueError: invalid literal for int() with base 10:
김판다t
2023. 6. 7. 12:51
astype으로 정수로 바꿀 수 없는 데이터가 있을 때 나타나는 에러이다
Example
import pandas as pd
s = pd.Series(['1', '2', 'one', '4'])
s
0 1
1 2
2 one
3 4
dtype: object
s는 문자열로 이루어진 시리즈인데 'one'과 같이 정수로 바꿀 수 없는 데이터가 있으면 astype으로 자료형을 정수로 바꿀 수 없다
s.astype('int')
ValueError: invalid literal for int() with base 10: 'one'
이럴 때는 astype 함수 대신 pd.to_numeric(링크 참고) 함수를 사용하자