-
판다스 replace파이썬(판다스, AI,데이터 분석) 2021. 6. 5. 15:13
데이터 프레임중 숫자에 "," 가 있어서 문자열로 인식되어 숫자열로 바꾸는 방법
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters# 숫자에 ','가 들어가서 문자열인 경우, 숫자열로 변환 후 계산 하는 법 import pandas as pd def column_cleaning(col): temp_list = [] # 빈 리스트 준비 for i in col: temp = int(i.replace("," , "")) # ","를 없애고, int로 변환한다. temp_list.append(temp) # 최종 변환한 데이터를 리스트에 추가 return temp_list replace split으로 나누기
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characterstmp = "12,578" # 확인 tmp """ output '12,578' """ a,b = tmp.split(",") """ output a = 12 b = 578 """ revenue_19_2 = int(a + b) revenue_19_2 '파이썬(판다스, AI,데이터 분석)' 카테고리의 다른 글
OOP (0) 2021.09.13 판다스 데이터 소수점 표시 하기 (0) 2021.06.05 판다스 인덱싱 (0) 2021.06.04 벡터와 매트릭스 ( Vectors and Matrices )-N131 (0) 2021.05.22 파이썬 판다스 inplace 옵션 (2) 2021.05.18