본문 바로가기

분류 전체보기

(102)
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;")
07_01_70. 두 list 중복값 추출하기 두개 데이터 프레임을 merge하려고 함 이 때, 컬럼이 너무 많아서 모두 key로 둘수도 없기 때문에 중복 컬럼들이 무엇인지 확인하고자 함 그래서 컬럼명들을 list화 해서 중복값 추출하고자 함 ## 두개 컬럼 명 list를 가지고 중복인 것 추출하고자 함 col_pv1 = df_pv1.columns.tolist() col_pv2 = df_pv2.columns.tolist() col_dup_pv = list(set(col_pv1).intersection(col_pv2))
07_01_69. list 내 값 중복 제거 # Python 3 code to demonstrate # removing duplicated from list # using collections.OrderedDict.fromkeys() from collections import OrderedDict # using collections.OrderedDict.fromkeys() # to remove duplicated # from list res = list(OrderedDict.fromkeys(l_features)) res
07_01_68. pd.pivot_table 컬럼명 prefix 컬럼명이 cd_cd의 value값 결합이 되도록 prefix 지정~ pd.pivot_table( df_goods , index = 'key', columns ='cd', values='qty').add_prefix('cd_')
07_01_67. 더미변수 생성하기 get_dummies import pandas as pd # dummy variable 생성 # drop_first = True : 첫번째 컬럼 base column으로 지정 pd.get_dummies(df_01['cd'] , prefix ='cd', drop_first=True)
10_05. Difference between timestamp (날짜,시간 차이 구하기) select * from MyTab T where TIMESTAMPDIFF(MINUTE,T.runTime,NOW()) > 20 TIMESTAMPDIFF(단위, 날짜1, 날짜2); SECOND : 초 MINUTE : 분 HOUR : 시 DAY : 일 WEEK : 주 MONTH : 월 QUARTER : 분기 YEAR : 연 출처: https://extbrain.tistory.com/78 [확장형 뇌 저장소]
10_04. 연속적인 log_id에 대한 시작, 끝 log_id 구해라 (Find the Start and End Number of Continuous Ranges) Since some IDs have been removed from Logs. Write an SQL query to find the start and end number of continuous ranges in table Logs. Order the result table by start_id. The query result format is in the following example: select min(log_id) as start_id ,max(log_id) as end_id from ( select log_id ,row_number()over(order by log_id) as log_no from logs ) a1 group by log_id-log_no ;