Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
Tags
- 三井住友カード
- 방콕
- Selenium
- PostgreSQL
- 釜つる
- CSV
- 熱海
- javascript
- PayPayフリマ
- 미츠이 스미토모
- pyenv
- 메르페이
- node.js
- 아타미
- typescript
- 카마츠루
- 산겐자야 맛집
- terraform
- 뮌헨
- vba
- 체코
- 일본 신용카드 추천
- 태국
- 프라하
- documentdb
- Python
- react.js
- PayPay
- 페이페이
- JenkinsFile
Archives
- Today
- Total
도쿄사는 외노자
Notebook에서 쓰는 함수 메모 본문
1. get_env
.env
파일에서 환경변수 취득
import os
from dotenv import load_dotenv
load_dotenv()
def get_env(key, default_value=""):
value = os.getenv(key, default_value)
return value
사용법
API_KEY=get_env("API_KEY")
parallel_execute
지정한 함수를 병렬기동
from concurrent.futures import ThreadPoolExecutor
def parallel_execute(function, args_list, max_workers=20):
futures = []
with ThreadPoolExecutor(
max_workers=max_workers, thread_name_prefix="thread"
) as pool:
for args in args_list:
future = pool.submit(function, *args)
futures.append(future)
return [fut.result() for fut in futures]
사용법
translate_story
함수를 병렬기동하고 싶은 경우, 함수의 파라메터의 배열을 만들어서 넘기면 됨
def translate_story(title, df):
df['story'] = df['name'].apply(lambda x: translate(x))
return df
grouped_by_title = df.groupby('title')
args = list(grouped_by_title)
result = parallel_execute(translate_story, args)
'Tech > Python' 카테고리의 다른 글
2024년의 Python 프로그래밍 (0) | 2024.02.05 |
---|---|
newspaper로 네이버 뉴스 가져오기 (0) | 2022.06.10 |
Beautiful Soup로 뉴스 내용 가져오기 (0) | 2022.06.10 |
Requests & BeautifulSoup 기본기 (0) | 2022.06.03 |
Pandas를 이용한 데이터 추출 (0) | 2022.05.27 |