File size: 706 Bytes
40fb94f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import pandas as pd
from utils.visualization import plot_engagement_heatmap, plot_engagement_over_time
from utils.preprocessing import preprocess_data
def analyze_engagement():
"""Analyze engagement data."""
# Load data
df = pd.read_json("data/raw/engagement_metrics.json")
df = preprocess_data(df)
# Group by hour for heatmap
df['hour'] = df['posting_time'].dt.hour
engagement_by_hour = df.groupby('hour')['engagement_rate'].mean().reset_index()
plot_engagement_heatmap(engagement_by_hour)
# Plot engagement over time
engagement_summary = df.groupby('posting_time').agg({'engagement_rate': 'mean'}).reset_index()
plot_engagement_over_time(engagement_summary) |