프로젝트 목적: '패스오더' 앱의 사용자 경험을 파악하기 위해 앱 리뷰 데이터를 파이썬으로 수집·전처리하고, 별점을 기준으로 긍정/부정을 나누어 전반적인 사용자 경험 평가를 보고자 한다.
구글 플레이스토어와 애플 앱스토어의 리뷰를 수집하기 위해 전용 라이브러리를 사용한다.
Bash
pip install google-play-scraper app-store-scraper pandas konlpy
import pandas as pd
from google_play_scraper import Sort, reviews_all
from app_store_scraper import AppStore
from konlpy.tag import Okt
import time
# 1. 구글 플레이스토어 리뷰 수집
print("구글 플레이스토어 리뷰 수집 중...")
try:
gp_reviews = reviews_all(
'com.paytalab.mkseo.passorder',
lang='ko',
country='kr',
sort=Sort.NEWEST
)
df_gp = pd.DataFrame(gp_reviews)[['content', 'score']]
print(f"구글 리뷰 수집 완료: {len(df_gp)}개")
except Exception as e:
print(f"구글 수집 중 에러 발생: {e}")
df_gp = pd.DataFrame(columns=['content', 'score'])
# 2. 애플 앱스토어 리뷰 수집 (수정된 포인트!)
print("애플 앱스토어 리뷰 수집 중...")
try:
# app_name을 영문 'passorder'로 수정하여 latin-1 인코딩 에러 방지
as_reviews = AppStore(
country='kr',
app_name='passorder',
app_id='1350702018'
)
as_reviews.review(how_many=1000)
# 리뷰 데이터가 있는지 확인 후 데이터프레임 생성 (KeyError 방지)
if as_reviews.reviews:
df_as = pd.DataFrame(as_reviews.reviews)[['review', 'rating']]
df_as.columns = ['content', 'score']
print(f"애플 리뷰 수집 완료: {len(df_as)}개")
else:
print("애플 리뷰를 찾을 수 없습니다.")
df_as = pd.DataFrame(columns=['content', 'score'])
except Exception as e:
print(f"애플 수집 중 에러 발생: {e}")
df_as = pd.DataFrame(columns=['content', 'score'])
# 3. 데이터 통합 및 전처리
print("데이터 통합 및 단어 추출 중...")
df_all = pd.concat([df_gp, df_as], ignore_index=True)
if df_all.empty:
print("수집된 데이터가 없어 종료합니다.")
else:
# 별점 기준 감성 라벨링
df_all['sentiment'] = df_all['score'].apply(
lambda x: 'Positive' if x >= 4 else ('Negative' if x <= 2 else 'Neutral')
)
# 형태소 분석기 (명사 추출)
# ※ 주의: Java(JDK)가 설치되어 있어야 여기서 에러가 나지 않습니다.
okt = Okt()
def get_nouns(text):
if not isinstance(text, str): return []
return [n for n in okt.nouns(text) if len(n) > 1]
# 분석할 데이터 필터링 (중립 제외)
df_filtered = df_all[df_all['sentiment'] != 'Neutral'].copy()
df_filtered['words'] = df_filtered['content'].apply(get_nouns)
# 4. 태블로용 데이터 변환 (Explode)
df_final = df_filtered.explode('words')
# 불필요한 단어 제거 및 결측치 제거
stop_words = ['패스', '오더', '진짜', '너무', '정말', '사용', '이용', '카페', '커피', '앱']
df_final = df_final[df_final['words'].notna()] # 단어가 없는 행 제거
df_final = df_final[~df_final['words'].isin(stop_words)]
# CSV 저장
df_final.to_csv('passorder_final_data.csv', index=False, encoding='utf-8-sig')
print("-" * 30)
print(f"최종 저장된 단어 데이터 개수: {len(df_final)}개")
print("작업 완료! 'passorder_final_data.csv'를 태블로에서 불러오세요.")
가장 쉬운 감성 분석 방법은 '별점 기반 라벨링'입니다. 텍스트에서 명사만 추출하여 태블로에서 사용하기 좋은 형태로 저장합니다.
# 3. 데이터 통합 및 전처리
print("데이터 통합 및 단어 추출 중...")
df_all = pd.concat([df_gp, df_as], ignore_index=True)
if df_all.empty:
print("수집된 데이터가 없어 종료합니다.")
else:
# 별점 기준 감성 라벨링
df_all['sentiment'] = df_all['score'].apply(
lambda x: 'Positive' if x >= 4 else ('Negative' if x <= 2 else 'Neutral')
)
# 형태소 분석기 (명사 추출)
# ※ 주의: Java(JDK)가 설치되어 있어야 여기서 에러가 나지 않습니다.
okt = Okt()
def get_nouns(text):
if not isinstance(text, str): return []
return [n for n in okt.nouns(text) if len(n) > 1]
# 분석할 데이터 필터링 (중립 제외)
df_filtered = df_all[df_all['sentiment'] != 'Neutral'].copy()
df_filtered['words'] = df_filtered['content'].apply(get_nouns)
# 4. 태블로용 데이터 변환 (Explode)
df_final = df_filtered.explode('words')
# 불필요한 단어 제거 및 결측치 제거
stop_words = ['패스', '오더', '진짜', '너무', '정말', '사용', '이용', '카페', '커피', '앱']
df_final = df_final[df_final['words'].notna()] # 단어가 없는 행 제거
df_final = df_final[~df_final['words'].isin(stop_words)]
# CSV 저장
df_final.to_csv('passorder_final_data.csv', index=False, encoding='utf-8-sig')
print("-" * 30)
print(f"최종 저장된 단어 데이터 개수: {len(df_final)}개")
print("작업 완료! 'passorder_final_data.csv'를 태블로에서 불러오세요.")