전체 글

이것저것
python 메모

[pandas] excel로 저장할 때 IllegalCharacterError가 뜰 때

pandas DataFrame을 excel로 저장할 때 IllegalCharacterError 같은 에러가 뜰 때가 있다. 이때 openpyxl로 저장하는 부분을 df.to_excel("test.xlsx", engine='openpyxl') xlsxwriter로 바꿔서 사용하면 에러가 안뜬다. df.to_excel("test.xlsx", engine='xlsxwriter')

python 메모

[sqlite] cx.read_sql, pd.read_sql 속도비교

pandas로 sqlite3 파일에서 300백만개 정도 되는 row의 데이터를 읽어올 일이 있었다. 하지만 이건 속도가 너무 느리다. connectorx와 비교해보자. 1. 사용법 비교 (1) pandas import sqlite3 import pandas as pd local_file_path = "/absolute/path/to/sqlite3/db" conn = sqlite3.connect(local_file_path) to_read = pd.read_sql( "SELECT * FROM '{tbl_name}'".format(tbl_name=tbl_name), conn, parse_dates=['timestamp'] ) (2) connectorx import connectorx as cx local_f..

개발

[websocket] (1) python websocket 서버 생성 & 클라이언트 테스트

python websockets 라이브러리를 사용해서 아주 간단한 websocket 서버를 만들어볼 수 있다. [참고문서] https://websockets.readthedocs.io/en/stable/ 1. 서버 생성 import asyncio import time import websockets import datetime import multiprocessing as mp # create handler for each connection if __name__ == "__main__": async def handler(websocket, path): while True: await websocket.send("[*] M1 from SERVER 1 "+str(datetime.datetime.now())..

개발

[ubuntu] mpi4py 설치 시 에러

ubuntu에서 pip install mpi4py로 mpi4py를 설치할 때 다음과 같이 에러메세지가 나는 경우가 있다. .... error: Cannot compile MPI programs. Check your configuration!!! [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for mpi4py Failed to build mpi4py ERROR: Could not build wheels for mpi4py, which is required to install pyproject.toml-based proje..

개발

[ChatGPT가 알려주는] overflow, underflow 파이썬 예시

Overflow and underflow are two concepts that refer to the limits of numerical representation in computing. They can happen in various programming contexts, including in Python, especially when dealing with floating-point numbers or integers that exceed the maximum or minimum size that can be represented. 1. Overflow Overflow occurs when a calculation produces a result that is larger than the max..

개발

[ubuntu] nohup 파일 생성 시 현재 날짜로 생기게 하기

nohup echo "hi" &> nohup$(date --iso).out & 이와 같이 $(date --iso)를 사용하면 현재 날짜를 기준으로 한 로그를 남길 수 있다.

python 메모

[matplotlib] 여러개의 다른 y축 그래프를 한 그래프에 그리기

같은 x축에 대해 서로 다른 y scale의 그래프를 그릴 일이 있다. 아래와 같이 그리면 된다. import matplotlib.pyplot as plt fig, ax = plt.subplots() fig.subplots_adjust(right=0.75) twin1 = ax.twinx() twin2 = ax.twinx() twin3 = ax.twinx() # Offset the right spine of twin2. The ticks and label have already been # placed on the right by twinx above. twin2.spines.right.set_position(("axes", 1.2)) twin3.spines.right.set_position(("axes"..

개발

[ubuntu] crontab 사용법 간단정리

1. Cron Job 등록 crontab -e로 job을 등록할 수 있다. # crontab -e 실행 후 아래 line 등록 # 매월 9일 21시 8분에 run.sh 실행 8 21 9 * * /home/user/.../run.sh # weekday(월-금) 매일 18시 0분에 run.sh 실행 0 18 * * 1-5 /home/user/.../run.sh 2. Cron Job 확인 crontab -l을 확인하면 등록한 job 목록을 보여준다. user@user-System-Product-Name:~/$ crontab -l MAILTO="" # Edit this file to introduce tasks to be run by cron. # # Each task to run has to be define..

개발

[ubuntu] 좀비 프로세스 죽이기(defunct)

ps -ef | grep defunct로 좀비 프로세스를 확인해보면 다음과 같이 나온다. 이때 34502가 parant process id인데 얘를 죽여주면 하위 프로세스들도 죽는다. sudo kill -9 34502 ps -ef | grep defunct user 32872 30725 0 14:49 pts/0 00:00:00 grep --color=auto defunct

python 메모

[python] list를 chunk로 나누는 방법들(메모)

ChatGPT가 알려준 리스트를 나누는 방법들을 정리해두고자 한다. 1. 리스트를 특정 크기로 자르기 def split_list_into_chunks(lst, chunk_size): """ Split a list into chunks of the specified size. Parameters: - lst: The list to be split. - chunk_size: The size of each chunk. Returns: A list of chunks, where each chunk is a sublist of the original list. """ return [lst[i:i + chunk_size] for i in range(0, len(lst), chunk_size)] my_list = [..

Fine애플
끄적끄적