반응형
1. 숫자를 천단위 컴마(",")로 추가하기
1.1 format() 함수 사용
format(숫자, ",")
>>> format(1234567890, ",")
'1,234,567,890'
1.2 f-strings 방식으로 문자열 포멧팅하기
f"{숫자:,d}" 또는 f"{숫자:,}"
>>> f"{1234567890:,d}"
'1,234,567,890'
>>> f"{1234567890:,}"
'1,234,567,890'
1.3 {} 기호 방식으로 문자열 포멧팅하기
"{:,d}".format(숫자) 또는 "{:,}".format(숫자)
>>> "{:,d}".format(1234567890)
'1,234,567,890'
>>> "{:,}".format(1234567890)
'1,234,567,890'
2. 숫자에서 천단위 컴마(",") 제거하기
2.1 split(), join() 함수 이용
"".join("숫자".split(","))
>>> "".join("1,234,567,890".split(","))
'1234567890'
2.2 replace() 함수 이용
"숫자".replace(",", "")
>>> "1,234,567,890".replace(",", "")
'1234567890'
728x90
반응형
'개발 > Python' 카테고리의 다른 글
| 구글 코랩 판다스 read_csv 인코딩 오류 (0) | 2024.02.17 |
|---|---|
| Windows pandas read_csv UnicodeDecodeError (0) | 2023.11.18 |
| Raspberry Pi - ImportError: libf77blas.so.3: cannot open shared object file: No such file or directory (0) | 2023.05.04 |
| PIP package backup / restore (0) | 2023.04.19 |
| Linux Anaconda Download, Install, Update (0) | 2023.04.18 |