Notice
Recent Posts
Recent Comments
Link
아미(아름다운미소)
pandas dataframe 자료형 변경 본문
import pandas as pd
# 예제 데이터
data = {
'A': [1.0, 2.0, 3.0], # float
'B': [4, 5, 6], # int
'C': ['x', 'y', 'z'] # string
}
# DataFrame 생성
df = pd.DataFrame(data)
# 모든 컬럼을 int64로 변환 시도
for col in df.columns:
df[col] = pd.to_numeric(df[col], errors='ignore', downcast='integer')
print(df)
print(df.dtypes)
'랭귀지 > SWIFT' 카테고리의 다른 글
pandas 컬럼값 변경 (0) | 2024.06.13 |
---|---|
pandas 중복행 제거 (0) | 2024.06.11 |
pandas list 형태로 컬럼명 지정하고 list 컬럼에 접미사 _calc 일괄 붙여서 컬럼 rename 후 일괄 fillna 적용 (0) | 2024.06.10 |
pandas 컬럼명에서 '_calc' 접미사 제거 (0) | 2024.06.10 |
pandas outer join 이름변경후 두열차감 (0) | 2024.06.09 |
Comments