在上一篇文章中,我們已經完成了資料欄位的統一。今天的任務,就是把 App Store 和 Google Play 的資料合併成一份完整的 DataFrame。
# 假設我們已經有 df_app_store 和 df_google_play
# 合併兩個資料集
combined_df = pd.concat([df_app_store, df_google_play], ignore_index=True)
# print(combined_df.head())
combined_df
假設我們只需要針對每個平台(App Store & Google Play)各抽取前 300 筆評論,
這樣可以確保資料在數量上平衡,可以參考下面範例的寫法。
import pandas as pd
# 假設我們已經有合併好的 combined_df
# 欄位包含:["title", "review", "rating", "date", "platform"]
# 依平台分組,取前 500 筆
limited_df = (
combined_df.groupby("platform", group_keys=False)
.apply(lambda x: x.head(500))
.reset_index(drop=True)
)
print(limited_df.shape)
print(limited_df["platform"].value_counts())
limited_df
👉 在下一篇文章中,我將示範如何進行 評論前處理,例如:移除 emoji、轉換時間格式、只保留特定欄位,讓資料更適合分析。