이 프로젝트는 이커머스 이벤트 히스토리 데이터를 활용하여 장바구니 취소 패턴을 분석하는 것을 목표로 한다.
분석을 통해 장바구니에서 상품이 취소되는 주요 원인을 탐색하고, 고객의 구매 전환율을 높이기 위한 전략을 제시한다.
id
컬럼을 BIGINT
로 변경하여 크기 불일치 이슈 해결 해결방안:
추가로 궁금한점
VIP 선정 기준: 구매 총액 상위 10% 고객 찾기 (python)
df.columns df['sum(price)'] = pd.to_numeric(df['sum(price)'], errors='coerce') vip_threshold = df['sum(price)'].quantile(0.9) print(f"VIP 기준 가격 (상위 10%): {vip_threshold:.2f}") df['user_type'] = df['sum(price)'].apply(lambda x: 'VIP' if x >= vip_threshold else 'Regular') vip_summary = df.groupby('user_type')['sum(price)'].sum().reset_index() print(vip_summary)
VIP 기준 가격 (상위 10%): 95.20
user_type sum(price)
0 Regular 776568.73
1 VIP 434969.70
일반 고객 장바구니 포기율
select (select count(*) from 2019_dec where event_type = 'remove_from_cart' and price > 0 and user_id in (select user_id from 2019_dec where event_type = 'purchase' group by user_id having sum(price) < 95)) / (select count(*) from 2019_dec where event_type = 'cart' and price > 0 and user_id in (select user_id from 2019_dec where event_type = 'purchase' group by user_id having sum(price) < 95)) * 100 as regular;
VIP 고객 장바구니 포기율
select (select count(*) from 2019_dec where event_type = 'remove_from_cart' and price > 0 and user_id in (select user_id from 2019_dec where event_type = 'purchase' group by user_id having sum(price) >= 95)) / (select count(*) from 2019_dec where event_type = 'cart' and price > 0 and user_id in (select user_id from 2019_dec where event_type = 'purchase' group by user_id having sum(price) >= 95)) * 100 ;
결과:
해결방안:
추가로 궁금한점
장바구니에서 제거된 상품이 다시 구매되는 시간을 분석하여 고객의 구매 패턴을 파악하고, 가격대별로 차이가 있는지 확인하는 것이 목표다.
select MIN(t.time_difference_minutes) min_time, ROUND(AVG(t.time_difference_minutes)) avg_time, MAX(t.time_difference_minutes) max_time, case when t.price < 5 then 'min_price' when t.price < 140 then 'low_price' when t.price < 210 then 'middle_price' when t.price < 280 then 'high_price' else 'max_price' end as price_category, count(*) FROM ( SELECT r.user_id, r.product_id, r.removed_time, p.event_type AS next_action, p.event_time AS next_action_time, r.price as price, (DATEDIFF(SUBSTR(p.event_time, 1, 10), SUBSTR(r.removed_time, 1, 10)) * 1440) + (SUBSTR(p.event_time, 12, 2) - SUBSTR(r.removed_time, 12, 2)) * 60 + (SUBSTR(p.event_time, 15, 2) - SUBSTR(r.removed_time, 15, 2)) time_difference_minutes FROM ( SELECT user_id, product_id, event_time AS removed_time, price FROM 2019_nov WHERE event_type = 'remove_from_cart' ) r JOIN ( SELECT user_id, product_id, event_type, event_time FROM 2019_nov WHERE event_type = 'purchase' ) p ON r.user_id = p.user_id AND r.product_id = p.product_id AND p.event_time > r.removed_time ORDER BY r.user_id, r.removed_time, p.event_time )t GROUP BY price_category```
remove_from_cart
(장바구니에서 제거)된 상품이 purchase
(구매)된 경우만 필터링 JOIN
을 사용해 같은 user_id
와 product_id
를 연결 FROM (
SELECT user_id, product_id, event_time AS removed_time, price
FROM 2019_nov
WHERE event_type = 'remove_from_cart'
) r
JOIN (
SELECT user_id, product_id, event_type, event_time
FROM 2019_nov
WHERE event_type = 'purchase'
) p
ON r.user_id = p.user_id
AND r.product_id = p.product_id
AND p.event_time > r.removed_time
DATEDIFF()
와 SUBSTR()
을 활용해 분 단위
로 계산 (DATEDIFF(SUBSTR(p.event_time, 1, 10), SUBSTR(r.removed_time, 1, 10)) * 1440) +
(SUBSTR(p.event_time, 12, 2) - SUBSTR(r.removed_time, 12, 2)) * 60 +
(SUBSTR(p.event_time, 15, 2) - SUBSTR(r.removed_time, 15, 2)) AS time_difference_minutes
상품 가격을 5개 구간으로 나누어 분석
CASE
WHEN t.price < 5 THEN 'min_price'
WHEN t.price < 140 THEN 'low_price'
WHEN t.price < 210 THEN 'middle_price'
WHEN t.price < 280 THEN 'high_price'
ELSE 'max_price'
END AS price_category
SELECT MIN(t.time_difference_minutes) AS min_time,
ROUND(AVG(t.time_difference_minutes)) AS avg_time,
MAX(t.time_difference_minutes) AS max_time,
price_category,
COUNT(*)
FROM (서브쿼리) t
GROUP BY price_category;
이커머스 비즈니스의 핵심은 고객 유지
이번 분석을 통해 고객 이탈을 줄이고 구매 전환율을 높이는 전략을 도출할 수 있었다.
이를 통해 비즈니스적 성장을 이루고, 고객 만족도를 높이는 방법을 설계할 수 있다
이커머스 비즈니스에서 가장 중요한 것은 ‘구매 경험’이며, 이를 최적화하는 것이 매출 상승의 핵심 요소이다.
앞으로도 더 효과적인 고객 맞춤형 마케팅 전략을 고민해봐야 할 것이다.