python_package/pandas

pandas.astype()

Xenrose 2024. 10. 11. 23:38

아래 내용은 pandas 2.0.3 버전으로 작성됨.

0. 바로 사용하기

DataFrame.astype(dtype)

  • dtype: 입력받은 type으로 변환하여 반환함.

 


1. 기본형

DataFrame

DataFrame.astype(dtype, 
                 copy=None, 
                 errors='raise')

Series

Series.astype(dtype, 
              copy=None, 
              errors='raise')

Index

Index.astype(dtype,
             copy=True)

 


2. 기능

  • dtype을 입력받아 해당 타입으로 변환하여 반환시켜줌.
    copy=False일 경우 반환하지 않고 원본 데이터를 바로 수정함.

 


3. 파라미터

dytpe

  • 입력 받은 dtype 인자값에 맞게 변환함.
  • dtype: int, float, str, bool, datetime, category

copy

  • copy = true: 복사본을 반환함.
  • copy = false: 복사본을 반환하지 않고 원본을 수정함.

errors

오류 발생시

  • errors = 'raise': 코드를 중단하고 오류 출력
  • errors = 'ignore': 무시하고 기존의 값으로 반환

 


ref

  1. https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.astype.html
  2. https://pandas.pydata.org/docs/reference/api/pandas.Series.astype.html
  3. https://pandas.pydata.org/docs/reference/api/pandas.Index.astype.html

'python_package > pandas' 카테고리의 다른 글

pandas.dropna()  (0) 2024.10.11
pandas.to_numeric()  (0) 2024.10.11
pandas.isna() / isnull()  (0) 2024.10.11
pandas.notna() / notnull()  (0) 2024.10.11
pandas.cut()  (0) 2024.10.11