일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- Excel
- dataframe
- Python
- PostgreSQL
- list
- Apache
- Mac
- Kotlin
- PySpark
- Java
- google apps script
- math
- PANDAS
- SQL
- c#
- numpy
- Github
- django
- GIT
- Google Excel
- array
- Tkinter
- 파이썬
- hive
- Redshift
- gas
- Google Spreadsheet
- matplotlib
- string
- Today
- Total
목록Python/Python ETC (56)
달나라 노트
image를 ASCII character를 이용한 그림으로 변환할 수 있습니다. 변환할 image인 apple.png는 다음과 같습니다. apple 로고를 변환해볼게요. import PIL.Image # list of ascii characters used when convert image to ascii text list_ascii_chars = ['@', '#', 'S', '%', '?', '*', '+', ';', ':', ',', '.'] # resize image according to a new width def resize_image(pil_obj_image, new_width): width, height = pil_obj_image.size # obj_image = image object ..
subprocess library를 이용해 Python에서 음악 파일을 재생할 수 있습니다. (본 예시는 Mac OS에서 실행되었습니다.) import subprocess subprocess.call(['afplay', 'music/test.mp3']) .위 예시처럼 간단하게 적으면 됩니다. subprocess의 call을 이용하며 인자로 list를 전달하는데 첫 번째는 afplay를 적어주고 두 번째에는 재생할 음악 파일이 있는 directory와 음악파일 이름을 적어주면 됩니다. import subprocess subprocess.call(['afplay', 'music/test.wav']) mp3 파일 뿐 아니라 wav 파일도 재생 가능합니다.
Web 페이지의 HTML코드를 가져온 다음에는 정보를 선택하는 작업이 필요합니다. 가져온 HTML 코드에서 내가 원하는 부분만 추출할 수 있어야 한다는 뜻입니다. import requests from bs4 import BeautifulSoup as bs URL = "https://www.naver.com" rq = requests.get(URL) soup = bs(rq.content, 'html.parser') li_list = soup.find_all('div', class_ = 'sc_timesquare') for li in li_list: ul = li.select('ul > li') for l in ul: print(l.get_text()) - Output 미세좋음 초미세좋음 위 코드를 봐봅시다..
import requests from bs4 import BeautifulSoup as bs URL = "https://www.naver.com" rq = requests.get(URL) soup = bs(rq.content, 'html.parser') print(soup) 어떤 Web 페이지의 HTML 코드를 가져오기 위해선 위처럼 requests와 bs4 libarary를 사용합니다. URL = "https://www.naver.com" rq = requests.get(URL) 위 부분은 정해진 URL에 대한 웹 자원을 요청하여 가져오는 역할을 합니다. soup = bs(rq.content, 'html.parser') print(soup) 그리고 BeautifulSoup의 기능을 사용합니다. 먼저 r..