목록Programming/Python (20)
Allen's 데이터 맛집
파이썬 기본 사칙연산 예시 코드 입니다. print(5//3 ) # 1. 몫 print(2**10) # 1024. 제곱 print(1+2 == 3) # True. 앞 뒤가 같나(bool). #'and 와 &' , 'or 와 |' 는 같음. print(abs(-5) # 5. 절대값 출력 print(pow(4,2)) # 16. 4의 2승 print(max(5,12)) # 12. print(min(5,12))# 5. print(round(3.14))# 3. 반올림 >>>1 >>>1024 >>>True >>>5 >>>16 >>>12 >>>5 >>>3
파이썬으로 csv 파일 읽기를 하는 도중 아래와 같은 오류가 떴습니다. unicodeescape' codec can't decode bytes in position 3-4: truncated \UXXXXXXXX escape 이 오류는 해석 그대로 파일 경로에 백슬래시(\)가 Unicode 이스케이프 문자로 해석되기 때문에 발생합니다. 이 문제를 해결하려면 다음과 같은 방법 중 하나를 선택할 수 있습니다: 1. 슬래시 사용: 백슬래시 대신 슬래시(/)를 사용하여 파일 경로를 지정하면 오류를 피할 수 있습니다. 예를 들어: df = pd.read_csv('csv/Upper_body.csv') 2. 백슬래시 이스케이프: 백슬래시를 이중으로 입력하여 이스케이프 처리할 수 있습니다. 즉, 백슬래시를 두 번 입력하..
데이터를 전처리를 할 때 기법으로 많이 쓰이는 정규화 표현식에 대해서 간단하게 알아보겠습니다 간단히 설명하자면 정해져있는 규칙에 따라서 문자를 추출하는 방법이라고 생각하시면 됩니다 정규화 표현식 p = re.compile('원하는 형태') m = p.match('비교할 문자열') : 주어진 문자열의 처음부터 일치하는지 확인. m = p.search('비교할 문자열') : 주어진 문자열 중에 일차하는게 있는지 확인. lst = p.findall('비교할 문자열) : 일치하는 모든 것을 리스트 형태로 반환 정규식 예 . : 하나의 문자를 의미. ^ : 문자열의 시작. $ : 문자열의 끝. #파이썬에서 정규 표현식을 지원하는 re 모듈 import re p = re.compile('ca.e') def prin..
저는Jupyter Notebook을 데이터 분석을 합니다. csv 파일을 불러올 때 경로가 어떻게 되어있는지 몰랐는데요, 간단한 os모듈을 가지고 확인이 가능합니다. 현재 경로 확인 import os print(os.getcwd()) # 실행결과 # C:\Users\Vector\ os모듈의 getcwd()함수를 사용하면 현재 지정되어 있는 경로를 확인할 수 있습니다. 경로 변경 import os os.chdir("../") print(os.getcwd()) # 실행결과 # C:\Users\ ../ 의 개수마다 현재 경로에서 한 단계식 내려갑니다.