Spaces:
Runtime error
Runtime error
Create traffic_analysis.py
Browse files- traffic_analysis.py +30 -0
traffic_analysis.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
from scipy.stats import pearsonr
|
3 |
+
|
4 |
+
df = pd.read_csv("traffic.csv")
|
5 |
+
|
6 |
+
total_pageviews = df['pageviews'].sum()
|
7 |
+
average_daily_pageviews = df['pageviews'].mean()
|
8 |
+
|
9 |
+
print("Total Pageviews:", total_pageviews)
|
10 |
+
print("Average Daily Pageviews:", average_daily_pageviews)
|
11 |
+
|
12 |
+
total_events = df['events'].sum()
|
13 |
+
event_distribution = df['events'].value_counts()
|
14 |
+
|
15 |
+
print("Total Events:", total_events)
|
16 |
+
print("Event Distribution:\n", event_distribution)
|
17 |
+
|
18 |
+
country_distribution = df.groupby('country')['pageviews'].sum()
|
19 |
+
|
20 |
+
print("Geographical Distribution:\n", country_distribution)
|
21 |
+
|
22 |
+
df['CTR'] = df['clicks'] / df['pageviews'] # Calculate CTR
|
23 |
+
overall_ctr = df['CTR'].mean()
|
24 |
+
|
25 |
+
print("Overall CTR:", overall_ctr)
|
26 |
+
print("CTR by Link:\n", df.groupby('link')['CTR'].mean())
|
27 |
+
|
28 |
+
correlation, _ = pearsonr(df['pageviews'], df['clicks'])
|
29 |
+
|
30 |
+
print("Correlation between Pageviews and Clicks:", correlation)
|