목록Programming/Python (20)
Allen's 데이터 맛집
zero fill 말그대로 함수 안에 매개변수의 숫자만큼 공간을 확보하고 값이 없으면 0으로 채우란 것입니다. 데이터 분석을 하시는분은 결측치를 평균값 등으로 채울때 많이 보시게 될 함수입니다. 이번 포스팅에선 사용법만 다루도록 하겠습니다. for num in range(1,21): print('대기번호 : '+str(num).zfill(3)) >>> 대기번호 : 001대기번호 : 002대기번호 : 003대기번호 : 004대기번호 : 005대기번호 : 006대기번호 : 007대기번호 : >>> 008대기번호 : 009대기번호 : 010대기번호 : 011대기번호 : 012
.ljust() 는 왼쪽으로 정렬, .rjust() 는 오른쪽 정렬 () 안의 매개변수는 어느정도 공백을 두는지 scores = {'수학':0,'영어':50,'코딩':100} for subject, socore in scores.items(): print(subject.ljust(8), str(socore).rjust(4), sep = ":") >>> 수학 : 0영어 : 50코딩 : 100
sep 명령어를 쓰면 csv 처럼 생성이 가능합니다. print('python','java',sep = ',') >>> python,java
실수를 표현할때, 자리수를 원하는대로 조절하고, 정수의 올림 반올림을 하고싶을때 사용하는 함수가있다. 반올림 소수점을 n번째 까지만 표현하고 반올림을 하고싶을때, round 함수를 사용하면된다. round(실수,n) n = 7/15 n round(n,2) round(n,4) round(n) type(round(n)) >>> 0.466666666666666 >>> 0.47 >>> 0.4667 >>> 0 >>> 원하는 자리수만 표현이 가능하다. 두번째매개변수를 비우면 소수점 첫번째자리를 반올림하여 나타낸다. round(1.77777777777777777777777777777) >>> 2 소수점이아닌 정수도 반올림을 할 수 있다. round(12345,-1) round(12345,-2) >>> 12340 >>..