Programming/Python (6) 썸네일형 리스트형 [Pandas] DataFrame 더 많은 행과 열 출력하기 1. 더 많은 행 출력하기 import pandas as pd pd.set_option('display.max_row', 100) 2. 더 많은 열 출력하기 import pandas as pd pd.set_option('display.max_columns', 100) [Python] 문자열 앞에 0을 채우는 방법(zfill, rjust) 1. zfill() 함수 사용 "3".zfill(3) # "003" "50".zfill(5) # "00050" "hi".zfill(5) # "000hi" 2. rjust() 함수 사용 "3".rjust(3, "0") # "003" "50".rjust(5, "0") # "00050" "hi".rjust(5, "a") # "aaahi" rjust는 0 이외에도 원하는 문자열을 채워줄 수 있는 특징이 있다. [Numpy] Numpy 행렬에 함수 적용하기 # Numpy version: 1.19.3 import math import numpy as np def sin_func(x): return math.sin(x) x = np.arange(0, 4*math.pi, step=math.pi/360) vecfunc = np.vectorize(sin_func) y = vecfunc(x) [Pandas] DataFrame 기간별 데이터 산출하기 1. resample() 사용하기 # 1달 단위 개수 확인 df["timestamp"] = pd.to_datetime(df["timestamp"]) df.set_index("timestamp").resample("1M").count() 참고) https://rfriend.tistory.com/494 [Pandas] DataFrame에서 특정 리스트에 해당하는 열 추출하기 isin() 사용하기 # pandas version : 1.3.3 mask = df["No"].isin([1,2,3]) df[mask] [Python] 파이썬에서 평균 구하는 방법 1. 리스트로 구하기 lst = [1,2,3,4,5,6,7,8,9,10] print(sum(lst) / len(lst)) 2. numpy 패키지로 구하기 import numpy as np np_array = np.array(lst) print(np_array.mean()) 이전 1 다음