Day2_Core_Data_Processing.md
Updated
This commit is contained in:
@@ -46,3 +46,18 @@ Transform the raw data into structured, insightful information using Python’s
|
||||
reviews_df["sentiment_score"] = reviews_df["review_text"].apply(
|
||||
lambda text: sid.polarity_scores(text)["compound"]
|
||||
)
|
||||
|
||||
|
||||
|
||||
### Aggregate sentiment data:
|
||||
|
||||
sentiment_summary = reviews_df.groupby("product_id").agg(
|
||||
avg_sentiment_score=("sentiment_score", "mean"),
|
||||
num_reviews=("review_text", "count")
|
||||
).reset_index()
|
||||
|
||||
|
||||
### Merge with sales data:
|
||||
|
||||
final_df = pd.merge(sales_summary, sentiment_summary, on="product_id", how="left")
|
||||
return json.loads(final_df.to_json(orient="records"))
|
||||
Reference in New Issue
Block a user