はじめに
本記事では、Google Playのレビューデータを用いて、Plotlyによる動的可視化を行います。
レビュー件数やスコア構成比を「日次/月次」で切り替えて確認できるUIを搭載し、さらにバージョン別の推移も分析します。
レビュー数が少ないタイトルでは日次の詳細が見やすく、長期運用のタイトルでは月次で全体の流れをつかむのが効果的です。
注意: レビュー取得方法は別記事「Google Playレビュー取得編」を参照してください。
本記事では取得済みのCSVファイルを使って可視化します。
1. 使用ライブラリとデータ準備
import pandas as pd
import plotly.graph_objects as go
import plotly.express as px
import numpy as np
# CSVファイルを読み込み(例:reviews_genshin_paged.csv)
df = pd.read_csv("reviews_genshin_paged.csv")
# 日付をdatetime化
df["at"] = pd.to_datetime(df["at"], errors="coerce")
# 日次・月次・バージョン列を作成
df["date"] = df["at"].dt.date
df["month"] = df["at"].dt.to_period("M").dt.to_timestamp()
2. 日次・月次を切り替え可能なレビュー件数推移
# 日次集計
daily_counts = df.groupby("date").size().reset_index(name="review_count")
# 月次集計
monthly_counts = df.groupby("month").size().reset_index(name="review_count")
# Plotlyで作成
fig = go.Figure()
# Trace 1: 日次
fig.add_trace(go.Scatter(
x=daily_counts["date"], y=daily_counts["review_count"],
mode="lines+markers", name="日次レビュー件数"
))
# Trace 2: 月次
fig.add_trace(go.Scatter(
x=monthly_counts["month"], y=monthly_counts["review_count"],
mode="lines+markers", name="月次レビュー件数", visible=False
))
# 切替ボタン
fig.update_layout(
title="日次・月次レビュー件数推移(切替UI付き)",
xaxis_title="日付/月", yaxis_title="レビュー件数",
template="plotly_white", height=600,
updatemenus=[{
"buttons": [
{"label": "日次表示", "method": "update",
"args": [{"visible": [True, False]}, {"title": "日次レビュー件数推移"}]},
{"label": "月次表示", "method": "update",
"args": [{"visible": [False, True]}, {"title": "月次レビュー件数推移"}]}
],
"direction": "right", "x": 0.35, "xanchor": "center", "y": 1.15, "yanchor": "top"
}]
)
fig.show()
# fig.write_html("plot_review_trend_switch.html", include_plotlyjs="cdn", full_html=True)
3. 日次・月次を切り替え可能なスコア構成比(100%積み上げ)
# 日次スコア構成比
score_daily = df.groupby(["date", "score"]).size().unstack(fill_value=0)
score_daily_ratio = score_daily.div(score_daily.sum(axis=1), axis=0) * 100
# 月次スコア構成比
score_monthly = df.groupby(["month", "score"]).size().unstack(fill_value=0)
score_monthly_ratio = score_monthly.div(score_monthly.sum(axis=1), axis=0) * 100
fig2 = go.Figure()
# 日次Trace
for s in sorted(score_daily_ratio.columns):
fig2.add_trace(go.Bar(
x=score_daily_ratio.index, y=score_daily_ratio[s],
name=f"★{s}", visible=True
))
# 月次Trace
for s in sorted(score_monthly_ratio.columns):
fig2.add_trace(go.Bar(
x=score_monthly_ratio.index, y=score_monthly_ratio[s],
name=f"★{s}", visible=False
))
fig2.update_layout(
barmode="stack",
title="日次・月次レビュー点数構成比(100%積み上げ)",
xaxis_title="日付/月", yaxis_title="構成比(%)",
yaxis=dict(range=[0, 100]),
template="plotly_white", height=600,
updatemenus=[{
"buttons": [
{"label": "日次表示", "method": "update",
"args": [{"visible": [True]*5 + [False]*5},
{"title": "日次レビュー点数構成比(100%積み上げ)"}]},
{"label": "月次表示", "method": "update",
"args": [{"visible": [False]*5 + [True]*5},
{"title": "月次レビュー点数構成比(100%積み上げ)"}]}
],
"direction": "right", "x": 0.35, "xanchor": "center", "y": 1.15, "yanchor": "top"
}]
)
fig2.show()
# fig2.write_html("plot_score_ratio_switch.html", include_plotlyjs="cdn", full_html=True)
4. バージョン別レビュー件数推移
# appVersion列の欠損を除外
df_ver = df.dropna(subset=["appVersion"])
# バージョン×日付のレビュー件数
ver_daily = df_ver.groupby(["date", "appVersion"]).size().reset_index(name="count")
fig3 = px.line(
ver_daily, x="date", y="count", color="appVersion",
title="バージョン別レビュー件数推移",
labels={"date": "日付", "count": "レビュー件数", "appVersion": "アプリバージョン"},
height=600
)
fig3.update_layout(template="plotly_white")
fig3.show()
# fig3.write_html("plot_version_count.html", include_plotlyjs="cdn", full_html=True)
5. バージョン別レビュー点数構成比(100%積み上げ)
# バージョン×スコアで集計
score_ver = df_ver.groupby(["appVersion", "score"]).size().unstack(fill_value=0)
# 構成比(%)
score_ver_ratio = score_ver.div(score_ver.sum(axis=1), axis=0) * 100
score_ver_ratio = score_ver_ratio.reset_index()
fig4 = px.bar(
score_ver_ratio, x="appVersion", y=[1,2,3,4,5],
title="バージョン別レビュー点数構成比",
labels={"value": "構成比(%)", "appVersion": "アプリバージョン", "variable": "スコア"},
barmode="stack", height=600
)
fig4.update_layout(template="plotly_white", yaxis=dict(range=[0, 100]))
fig4.show()
# fig4.write_html("plot_version_ratio.html", include_plotlyjs="cdn", full_html=True)
データ仕様と分析上の注意点
- Google Playのレビューはユーザー1人につき1件のみ保持されます。
- 再投稿すると過去レビューは上書きされます。
- そのため、過去スコアは「傾向把握」として参考値で扱うのが適切です。
- レビュー数が少ないタイトルは日次、多い/長期運用タイトルは月次で集計すると可読性が向上します。
appVersion
が欠損しているレビューはバージョン分析から除外するのが無難です。
まとめ
- Plotlyの切替UIで日次/月次の視点を自由に変更可能。
- グラフを高めに設定(height=600)することで長期データも見やすくなる。
- バージョン別推移を併せて確認することで、評価変動の原因を探りやすくなる。
- データ量や期間に応じて最適な粒度(日次・月次)で可視化を行うことが重要です。