분석72 M+3 의 재 구매율, M+(1,2,3)의 재 구매율 M+3 의 '재구매율' 이란? 예를 들어 1월의 (신규) 구매자들 중에 4월달에도 재구매를 한 비율을 뜻한다. M+(1,2,3) 의 '재구매율' 이란? 예를 들어 1월의 (신규) 구매자들 중에 2월부터 4월까지 재구매를 한 비율을 뜻한다. 이를 SQL를 이용하여 계산해보도록 하자. 1. 아래와 같이 tbl_uesr, tbl_order 라는 테이블이 있다고 가정합니다. 2. 2019년1월 부터 2019년 12월까지 12개월을 대상으로 'M+3 재구매율' select base_mon.now_dt , count(distinct base_mon.user_id) as cnt_curmon , count(distinct future_mon.user_id) as cnt_nextmon , count(distinct fu.. 2020. 6. 25. DBeaver 로 AWS Athena 접속하기 1. DBeaver의 데이터베이스 접속 화면에서 Athena 를 검색하여 선택합니다. 2. 선택을 하면 아래 그램과 같이 - Region - S3 location - Access Key - Scret Key 를 입력해줘야 합니다. 3. 위 창의 입력정보를 얻기 위해서는 웹상에서 AWS의 콘솔에 로그인을 합니다. 창의 오른쪽 상단을 보면 Region ('서울'이라고 나와있는)을 선택하는 화면이 있는게 여기서 Region 코드를 얻을 수 있습니다. 버지니아 북부라면 us-east-1 이 리젼이 됩니다. 4. 위의 지역 옆에 내 계정이 나와 있는 부분을 클릭하면 아래와 같이 '내 보안 자격증명'이라는 메뉴가 보입니다. 클릭하여 들어갑니다. 5. 아래와 같은 화면이 나타나는데 '엑세스 키 만들기' 버튼을 클릭하.. 2020. 6. 9. Python : 위도.경도로 TimeZone 구하기 Python에서 위도와 경도 값으로 TimeZone 구하기 먼저 'timezonefinder' 라는 패키지를 설치하여야 한다. pip install timezonefinder 사용법은 아래와 같이 간단하다. from timezonefinder import TimezoneFinder tf = TimezoneFinder() latitude, longitude = 52.5061, 13.358 tf.timezone_at(lng=longitude, lat=latitude) # returns 'Europe/Berlin' * 만일 아래와 같이 DataFrame에 위.경도의 값이 있다고 하면 from timezonefinder import TimezoneFinder my_func = TimezoneFinder().ti.. 2020. 3. 10. with statement in SQL with 문을 사용하면 SQL 문장을 매우 직관적으로 사용할 수 있는데, 다음과 같이 몇 가지 형태로 사용할 수 있다. 1. sub query를 with 문 으로 with list1 as ( select id, area from tbl_address where area = 'seoul' ), list2 as ( select subject, avg(score) from tbl_score where id in (select id from list1) group by subject ) select * from list2; 물론 위의 쿼리는 with문을 사용하지 않고 처리할 수도 있지만, with 문안의 가상테이블에서 다른 가상테이블을 조건으로 사용할 수도 있으며 복잡한 쿼리를 단순하게 직관적으로 표현할 수 있.. 2020. 1. 29. How To Calculate Cohort Retention in SQL Losing users sucks. Losing customers really sucks. If you’re a startup, you know that Retention is King. You should always be measuring and improving your user retention, so you can keep more users over time. In this post, we’ll show you how to calculate user retention on your own data in SQL. Defining retention If Gloria used the product on Monday and used the product again on Tuesday, she is .. 2020. 1. 7. python : pd.to_numeric() VS astype(np.float64) import pandas as pd import numpy as np df = pd.DataFrame(np.random.randint(10**5, 10**7, (5,3)), columns=list('abc'), dtype=np.int64) df a b c 0 2368596 282593 7649457 1 6486779 5348256 790672 2 8468404 4682970 2904873 3 2271514 2908642 9272301 4 7811256 3652968 6715015 df.dtypes a int64 b int64 c int64 dtype: object df['a'] = df['a'].astype(float) df.dtypes a float64 b int64 c int64 dtype: obje.. 2019. 11. 27. Python : Seaborn Visualization import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sns # 데이터셋 iris = sns.load_dataset('iris') titanic = sns.load_dataset('titanic') tips = sns.load_dataset('tips') flights = sns.load_dataset('flights') x = iris.petal_length.values sns.rugplot(x) sns.kdeplot(x) sns.distplot(x, rug=True, kde=True, bins=50) plt.hist(x, bins=50) (array([ 2., 2., 7., 13., 13., 11.. 2019. 11. 25. Python : Pandas Visualization pandas의 plot은 내부적으로 matplotlib.pyplot을 이용한다. import numpy as np import pandas as pd import matplotlib.pyplot as plt df1 = pd.DataFrame(np.random.randn(100, 3), index=pd.date_range('1/1/2019', periods=100), columns=['A', 'B', 'C']).cumsum() df1 A B C 2019-01-01 -0.896370 -1.962732 1.584821 2019-01-02 -0.248402 -3.101740 0.370419 2019-01-03 0.622560 -3.979711 1.666569 2019-01-04 1.239019 -3.443114.. 2019. 11. 25. Python : timedelta(months=3) 방법 Python에서 사용할 수 있는 시간의 차이에 관련된 모듈은 datetime.timedelta 가 있습니다.아래와 같이 사용할 수 있습니다.import datetime as dt now = dt.datetime.now()delta = dt.timedelta(hours=3)diff = now - delta 이 모듈에서 사용할 수 있는 옵션은 dayshourssecondsweeks 등이 있지만, months, years를 사용할 수는 없습니다. 그 대안으로 사용할 수 있는 모듈이 relativedelta 라는 모듈입니다.그리고 그 사용은 아래와 같습니다.from dateutil.relativedelta import relativedeltaimport datetime as dt now = dt.datetime.. 2019. 11. 12. RFM Analysis (RFM 분석) R : recency (최근 구매일) F : frequency (구매 횟수) M : monetary (구매 금액 합계) 에 따른 고객군 구분 2019. 9. 24. 이전 1 ··· 3 4 5 6 7 8 다음