일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- tensorflow
- ubuntu
- Excel
- Linux
- 다이어트
- pandas
- PyQt5
- 날짜
- PER
- python
- 리눅스
- urllib
- Unity
- ASP
- MySQL
- port
- 맛집
- 유니티
- GIT
- MS-SQL
- PyQt
- 함수
- swift
- mssql
- 라즈베리파이
- sqlite
- javascript
- IOS
- node.js
- flutter
아미(아름다운미소)
from pynput import keyboard, mousefrom pynput.keyboard import Controller, Keyimport threadingimport timefrom datetime import datetimeimport ctypesimport osimport platform# 설정IDLE_TIME_LIMIT = 300 # 5분 이상 비활동 시CHECK_INTERVAL = 10 # 활동 체크 주기keyboard_controller = Controller()last_activity_time = time.time()# 사용자 입력 감지 핸들러def on_input_activity(event): global last_activity_time la..
python -m cProfile -o profile_results.prof your_script.pypython -m pstats profile_results.prof
import numpy as npimport pandas as pdfrom numba import njit@njitdef numba_select(condlist, choicelist, default=0): output = np.full(condlist[0].shape, default) for cond, choice in zip(reversed(condlist), reversed(choicelist)): output = np.where(cond, choice, output) return output # NumPy 배열 반환# 예시 데이터condlist = [np.array([True, False, False]), np.array([False, True, False])]choi..
import numpy as npimport pandas as pdimport multiprocessing as mpfrom functools import partialdef process_chunk(df_chunk, conditions, choices, default): # 각 청크에 np.select 적용 result = np.select(conditions, choices, default=default) return pd.Series(result, index=df_chunk.index)def parallel_select(df, conditions, choices, default='default', num_processes=None): if num_processes is None..
import pandas as pddef report_memory_usage(df: pd.DataFrame, sort: bool = True, top: int = None) -> pd.DataFrame: """ DataFrame의 열별 실제 메모리 사용량을 GB 단위로 리포팅합니다. 'Index'는 제외됩니다. Args: df (pd.DataFrame): 측정할 DataFrame sort (bool): 메모리 사용량 기준 정렬 여부 (default: True) top (int): 상위 N개 열만 출력 (default: None: 전체) Returns: pd.DataFrame: 열별 메모리 사용량(GByte), dtype 포함 ..
cols = ['col1', 'col2', 'col3'] # category로 바꿀 컬럼 리스트df[cols] = df[cols].apply(lambda x: x.astype('category'))import pandas as pdimport numpy as np# 예시 데이터 생성df = pd.DataFrame({ 'col1': np.random.choice(['apple', 'banana', 'cherry'], 1_000_000), 'col2': np.random.choice(['red', 'green', 'blue'], 1_000_000), 'col3': np.random.choice(['small', 'medium', 'large'], 1_000_000)})# 🔍 메모리 사용량..
import pandas as pddf1 = pd.DataFrame({'A': [1, 2], 'B': [3, 4]}, index=['x', 'y'])df2 = pd.DataFrame({'A': [5, 6], 'C': [7, 8]}, index=['x', 'y'])# Left join with drop=Falseresult = df1.join(df2.set_index('A', drop=False), how='left', # 명시적으로 left join 지정 lsuffix='_left', rsuffix='_right')print(result)
from concurrent.futures import ThreadPoolExecutorimport numpy as npimport pandas as pddef safe_parallel_merge(df1, df2, left_key, right_key=None, n_partitions=4, how='left'): """ 개선된 병렬 merge 함수 - 안정성 강화 버전 Parameters: - df1: 왼쪽 DataFrame - df2: 오른쪽 DataFrame - left_key: df1의 조인 키 (컬럼명 또는 컬럼 리스트) - right_key: df2의 조인 키 (None이면 left_key와 동일) - n_partitions: 분할 개수 - ..
import polars as pldef process_dataframe_optimized_pl(dict_df_types: dict, df: pl.DataFrame) -> pl.DataFrame: def handle_column(col: str, dtype: str) -> pl.Expr: try: expr = pl.col(col) if dtype == 'int': return expr.cast(pl.Int32).fill_null(0).alias(col) elif dtype == 'float': return expr.cast(pl.Float32).fill_null(0).alia..
import pandas as pddef convert_object_columns_to_str(df: pd.DataFrame) -> pd.DataFrame: """ Pandas DataFrame에서 object 타입 컬럼을 모두 문자열(str)로 변환합니다. Parameters: df (pd.DataFrame): 변환할 DataFrame Returns: pd.DataFrame: 문자열 컬럼이 str 타입으로 변환된 DataFrame """ df = df.copy() for col in df.select_dtypes(include='object').columns: df[col] = df[col].astype(str) ..