Python/tip of python
-
xlwings 라이브러리에서 좌표로 내용 입력하는 함수Python/tip of python 2020. 8. 19. 08:59
xlwings에서 내용입력 시 좌표가 아닌 A3, V2 같은형태로 위치를 지정한다. 좌표(row, column)와 내용과 시트명을 쓰면 내용 입력하는 형태의 함수. Z 뒤까지 쓰려면, alph에 Z 뒤로 계속 연결해서 더 입력하면 된다. def cell_w(x,y,cont,sheet): alph = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' w_lo = alph[y-1] + str(x) sheet.range(w_lo).value = cont return
-
python - 빠진 자리 data (missingno)Python/tip of python 2020. 7. 20. 20:58
Pandas 등에서 빠진 data 자리 : NaN = Not a Number NaN은 연산에서 빠짐 df['column명'].mean() # NaN 빼고 평균 구함df['column명'].fillna(0) #빈자리를 0으로 채움 df['column명'].fillna(0).mean() # 빈자리 0으로 채우고, 합쳐서 평균 구함 [빈자리 data를 시각화 해주는 라이브러리 : missingno] 예시 만들기 부터 하면, %matplotlib inlineimport pandas as pdimport numpy as pddf = pd.DataFrame(np.random.rand(100,100))cond = df > 0.3df[cond]# 0.3보다 큰 값만 남기고 남은 것은 빈칸 처리 : NaN으로 채워짐 d..
-
installing libraries on condaPython/tip of python 2020. 7. 20. 16:39
Although I've already installed some libraries, Jupyter Notebook doesn;t find them out from time to time. At that time you'd better switch the way to install them. If you don't use conda, just use : pip install openpyxl If you use conda, I'd recommend : conda install -c anaconda openpyxl instead of simply conda install openpyxl Because there are issues right now with conda updating (see GitHub I..
-
data frame 문자열 다루기Python/tip of python 2020. 7. 16. 20:24
[엑셀에서 우선 읽어오자] df = pd.read_excel('화일이름.xlsx', index_col='기준이 될 컬럼 이름') [슬라이싱으로 읽어오기] df['곡명'].str[0] #맨 앞글자 df['곡명'].str[:10] #앞에서 10자까지 [단어별로 문자열 쪼개기] df['곡명'].str.split() #곡명 별 문자열에서 단어별 시리즈 생성 df['곡명'].str.split(expand=True) # 단어별 순서데로 0 1 2 ~ 컬럼생성 df['곡명'].str.split(expand=True)[1] # 두 번째 단어만 선택 [좌우 스페이스(white space) 문자열 삭제] df['곡명'] = df['곡명'].str.strip() ######## 스페이스 삭제 후 재 저장 왼 쪽 스페이스 없..