Hygwell / traffic_analysis.py
Hemavathineelirothu's picture
Create traffic_analysis.py
5146163 verified
raw
history blame contribute delete
887 Bytes
import pandas as pd
from scipy.stats import pearsonr
df = pd.read_csv("traffic.csv")
total_pageviews = df['pageviews'].sum()
average_daily_pageviews = df['pageviews'].mean()
print("Total Pageviews:", total_pageviews)
print("Average Daily Pageviews:", average_daily_pageviews)
total_events = df['events'].sum()
event_distribution = df['events'].value_counts()
print("Total Events:", total_events)
print("Event Distribution:\n", event_distribution)
country_distribution = df.groupby('country')['pageviews'].sum()
print("Geographical Distribution:\n", country_distribution)
df['CTR'] = df['clicks'] / df['pageviews'] # Calculate CTR
overall_ctr = df['CTR'].mean()
print("Overall CTR:", overall_ctr)
print("CTR by Link:\n", df.groupby('link')['CTR'].mean())
correlation, _ = pearsonr(df['pageviews'], df['clicks'])
print("Correlation between Pageviews and Clicks:", correlation)