본문 바로가기

언어 꿀Tip

(87)
08_02. loading bar (로딩바) in r install.packages('progress') library(progress) pb
07_01_77. 그룹별 describe() 구하기 : groupby describe() # Making GroupBy object grouped = df.groupby('cd') ## 1) grouped.describe()['cnt'] ## 2) T : transpose grouped.describe()['cnt'].T 2) output 예시
07_01_76. period_range 날짜생성 후 년월 string 변환 pd.period_range('20180101', '20210801', freq='M').astype(str).str.replace("-","")
[hive/impala] 정규표현식 이용한 숫자 추출하기 select nm ,regexp_extract(nm,'[0-9]+', 0) as number from table
07_01_74. dataframe difference of dates df_agg = df_agg.sort_values(['cust_distn_no','oper_dt']).reset_index(drop=True) # column type 변경 df_agg['oper_date'] = pd.to_datetime(df_agg['oper_dt']) # lag변수 생성 df_agg['lag_oper_date'] = df_agg.groupby(['cust_distn_no'])['oper_date'].shift(1) df_agg_01 = df_agg[~df_agg['lag_oper_date'].isnull()] # difference df_agg_01['diff_oper_date'] = (df_agg_01['oper_date']-df_agg_01['lag_oper_date']).dt...
07_02_02. [codility] CyclicRotation python import numpy as np 가 실행되지 않아, 결국 다른 분들이 작성한 것을 참고하여 풀어봄! Task description An array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9, 7] (elements are shifted right by one index and 6 is moved to the f..
07_02_01. [codility] OddOccurrencesInArray collection 모듈 Counter 이용 문제 ! Task description A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be paired with another element that has the same value, except for one element that is left unpaired. For example, in array A such that: A[0] = 9 A[1] = 3 A[2] = 9 A[3] = 3 A[4] = 9 A[5] = 7 A[6] = 9 the elements at indexes 0 and 2 have valu..
10_02. aws s3로 directly parquet 파일 읽고 저장하기 import io import os import pandas as pd import numpy as np import datetime, time import awswrangler as wr # 저장하기 S3_PATH = 'work-space/path/' S3_BUCKET = 'dmd-sandbox-zone-bucket' # bucket filename = 'filename.parquet' write_path = f's3://{S3_BUCKET}/{S3_PATH}{filename}' wr.s3.to_parquet( df=df_tmp, path=write_path) # 불러오기 S3_PATH = 'work-space/path/' S3_BUCKET = 'dmd-sandbox-zone-bucket' # buck..
10_01. lambda 트리거(trigger) 이용한 자동 실행 설정 주기적으로 lambda함수를 자동실행하는 방법으로 CloudWatch Events 를 이용해보려고 한다. CloudWatch Events의 트리거를 추가해서 설정할 수 있다! 기존에 생성해 놓은 규칙을 사용한다면, 아래와 같이 기존 규칙을 체크하고 아래 화살표를 눌러 해당되는 것을 선택하면 된다. 새롭게 추가하고 싶은 경우, cron과 rate를 이용하여 규칙을 설정해야 한다. 규칙 이름, 규칙 설명, 에약표현식을 입력하자 공홈 설명서 에 자세한 예시와 설명이 있으니 참고!
07_01_71. sql로 데이터프레임(dataframe) 다루기, pysqldf sql을 활용하여 데이터프레임 join 등등 하기 위한 기본 구문 from pysqldf import SQLDF import pandas as pd import io txt = io.StringIO(""" col1col2 a1 b2 c3 d4 """) df = pd.read_csv(txt, sep="\t") df sqldf = SQLDF(globals()) sqldf.execute("select * from df limit 3;")