pandas.astype()

SeungHyun·2023년 8월 24일
0

Pandas

목록 보기
3/6
post-thumbnail

아래 내용은 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
profile
어디로 가야하오

0개의 댓글

관련 채용 정보