Download scripts/analyze_engagement.py from Fred808/Insta-AI: direct link, hf CLI and curl.
- Browser
- Download file 706 Bytes
-
https://huggingface.co/spaces/Fred808/Insta-AI/resolve/main/scripts/analyze_engagement.py
- Command line
-
hf download hf://spaces/Fred808/Insta-AI/scripts/analyze_engagement.py
-
curl -L -o analyze_engagement.py https://huggingface.co/spaces/Fred808/Insta-AI/resolve/main/scripts/analyze_engagement.py
706 Bytes
| 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) |