da-ta ta-da

데이터 분석 인강 5주차 : Push 발송 시간, 로그 데이터 본문

Data Analyst

데이터 분석 인강 5주차 : Push 발송 시간, 로그 데이터

jess1015 2022. 5. 22. 17:28

1. Push 발송 시간대 의사결정

- 가장 주문이 많이 일어나는 피크 시점을 분석해 Push 발송하기

order_by_hour = retail.set_index('InvoiceDate').groupby(lambda date: date.hour).count()['CustomerID'] # 가장 주문이 많은 시간대 확인

def half_an_hour(date): # 구매 시간대 30분 단위로 분석하기
    minute = ":00"
    if date.minute > 30:
        minute = ":30"
    hour = str(date.hour)
    if date.hour < 10:  # 깔끔한 표기를 위해
        hour = '0' + hour
    return hour + minute
order_by_hour_half = retail.set_index('InvoiceDate').groupby(half_an_hour).count()['CustomerID']

- Push 개인화

  - 유저별로 구매 시점이 다름, 가장 많이 구매한 시간대를 찾아 해당 시간대에 Push 발송

# 사용자별 시간별 주문량
order_count_by_hour = retail.set_index('InvoiceDate').groupby(['CustomerID', lambda date: date.hour]).count()['StockCode']
order_count_by_hour

# 사용자별 주문 피크 타임
idx = order_count_by_hour.groupby('CustomerID').idxmax() 
result = order_count_by_hour.loc[idx]

 

2. 로그 데이터

- 웹서버 로그 데이터를 활용해 Funnel 분석 가능

- 웹서버 로그 데이터: 유저 행동을 로그로 기록하는 파일; ip, session id, user id, datetime, request, url 등으로 구성

# 연산을 위해 datetime 포맷으로 변경
logs['datetime'] = logs['datetime'].apply(lambda date: date.replace('[', '').replace(']',''))
logs['datetime'] = pd.to_datetime(logs['datetime'], format ='%d/%b/%YT%H:%M:%S')

# 퍼널 스텝 dataframe 생성
funnel_dict = {'/product_list' : 1, '/product_detail' : 2, '/cart' : 3, '/order_complete' : 4}
funnel_steps = pd.DataFrame.from_dict(funnel_dict, orient = 'index', columns = ['step_no'])

grouped = logs.groupby(['session_id', 'url'])['datetime'].agg(np.min) # 동일한 유저가 다른 세션으로 접속한 케이스는 분리해서 분석해야 하므로 user_id가 아닌 session_id를 기준으로 그루핑, session_id와 url로 그루핑하여 가장 빠른 시간대의 이벤트 추출(유저 여정이 다양하므로)
grouped = pd.DataFrame(grouped).merge(funnel_steps, left_on = 'url', right_index = True)  

funnel = grouped.reset_index().pivot(index = 'session_id', columns = 'step_no', values = 'datetime')
funnel.columns = funnel_steps.index

# 퍼널별 카운트 
step_values = [funnel[index].notnull().sum() for index in funnel_steps.index] # for문 output을 즉시 리스트로

Comments