PAPAGO OCR번역 API코드
·
Python/유용한 python 코드
코드 서비스를 사용하기 전에 반드시 서비스 설명란에서 무료 이용 범위를 정독한 후 사용하기를 권장한다. 1. 여러 확장자의 이미지 가져오기 names = [".jpg", ".jpeg", ".png", ".gif", ".bmp", ".tiff", ".tif", ".webp"] TITLE = "폴더의 제목" # 번역할 이미지가 들어있는 폴더의 제목을 넣어준다. API_KEY_ID = "Client ID를 넣어준다" API_KEY = "Client Secret을 넣어준다" 2. 폴더 생성 함수 import os def createFolder(directory, ROOTPATH = ''): ''' directory = 폴더명, ROOTPATH = 절대경로를 지정할 때 사용하면 좋습니다. 생성된 폴더의 절대(존재..
Python, (리스트 요소별 개수 파악) 딕셔너리에서 최빈값 구하기
·
Python/유용한 python 코드
# from collections import Counter --> Counter([1, 2, 3, 3])을 사용해도 됨 def count_list_elements(word): for letter in word: if letter not in counter: counter[letter] = 0 counter[letter] += 1 return counter print(count_list_elements([1, 2, 3, 3]), count_list_elements('test1')) def find_max(word): counter = count_list_elements(word) # 여기서 위의 함수가 들어감 max_count = -1 for letter in counter: if counter[lett..
Python, 리스트 요소별 개수 파악
·
Python/유용한 python 코드
# from collections import Counter --> Counter([1, 2, 3, 3])을 사용해도 됨 def count_list_elements(word): for letter in word: if letter not in counter: counter[letter] = 0 counter[letter] += 1 return counter print(count_list_elements([1, 2, 3, 3]), count_list_elements('test1'))
Python, 판다스에서 열, 행 이름 안 잘리고 전부 보이게 하기
·
Python/유용한 python 코드
pd.set_option('display.max_columns', 10) pd.set_option('display.max_rows', 10) 뒤의 숫자를 보고싶은만큼 늘리면 된다
Python, 시계열 데이터 컬럼 만들어주기
·
Python/유용한 python 코드
test_data_1 = pd.DataFrame({'집계일자' : ['20210919', '20210919','20210919','20210919','20210919','20210919'], \ '집계시' : ['8', '9', '10', '11', '12', '13']}) display(test_data_1, "위의 df가 아래처럼 변함") all_2017_copy1 = test_data_1.copy() for i in range(all_2017_copy1['집계일자'].shape[0]): result1 = str(all_2017_copy1['집계일자'][i])[:4] result2 = result1 + '-' result3 = result2 + str(all_2017_copy1['집계일자'][i])[..
Python, 계단형 상관계수 히트맵 그리기
·
Python/유용한 python 코드
# df.drop('date', axis = 1) # 드랍할 컬럼 import matplotlib.pyplot as plt import numpy as np import seaborn as sns import warnings warnings.filterwarnings(action='ignore') df = titanic plt.figure(figsize = (16, 16)) mask = np.zeros_like(df.corr(), dtype=np.bool) # corr을 다른 것으로 바꾸면 다른 상관계수 그래프를 그릴 수도 있음 mask[np.triu_indices_from(mask)] = True sns.heatmap(df.corr(), annot = True, fmt = '.3f', mask = ma..
Python, txt파일 읽어오기
·
Python/유용한 python 코드
txt_test_list = [] txt_test_list2 = [] ROOT_PATH = "folder_for_test//6_txt_test" f = open(ROOT_PATH + '//test.txt', 'r', encoding='UTF8') while True: line = f.readline() # readline = 한 줄씩 읽어옴, readlines = 모든 각각의 줄을 읽어서 리스트에 넣음, read = 파일 내용 전체를 문자열로 리턴 txt_test_list.append(line) if not line: break; f.close() for i in txt_test_list: txt_test_list2.append(i.strip()) # strip이란 함수가 있음 신기방기
Python 폴더 생성 함수
·
Python/유용한 python 코드
import os def createFolder(directory, ROOTPATH = ''): ''' directory = 폴더명, ROOTPATH = 절대경로를 지정할 때 사용하면 좋습니다. 생성된 폴더의 절대(존재한다면)경로를 directory명 + _PATH 변수로 반환합니다. ''' try: if not os.path.exists(directory): os.makedirs(ROOTPATH + directory) globals()["{}_PATH".format(directory)] = ROOTPATH + directory except OSError: print (directory, "폴더를 생성할 수 없습니다.")