|
@@ -11,7 +11,7 @@ from pathlib import Path
|
|
|
task_dir = Path(__file__).parent
|
|
task_dir = Path(__file__).parent
|
|
|
output_dir = task_dir / "output"
|
|
output_dir = task_dir / "output"
|
|
|
|
|
|
|
|
-csv_files = [f for f in output_dir.glob("*.csv") if '_分析' not in f.name]
|
|
|
|
|
|
|
+csv_files = [f for f in output_dir.glob("*.csv") if f.stem.count('_') == 1]
|
|
|
if not csv_files:
|
|
if not csv_files:
|
|
|
print("没有找到数据文件,请先运行 query.sql")
|
|
print("没有找到数据文件,请先运行 query.sql")
|
|
|
exit(1)
|
|
exit(1)
|
|
@@ -152,7 +152,7 @@ for category in valid_categories:
|
|
|
|
|
|
|
|
log()
|
|
log()
|
|
|
|
|
|
|
|
-log("【各品类 Top 3 渠道】")
|
|
|
|
|
|
|
+log("【各品类 Top 5 渠道】")
|
|
|
log("-" * 80)
|
|
log("-" * 80)
|
|
|
|
|
|
|
|
for category in valid_categories:
|
|
for category in valid_categories:
|
|
@@ -162,9 +162,13 @@ for category in valid_categories:
|
|
|
if len(row) == 0:
|
|
if len(row) == 0:
|
|
|
continue
|
|
continue
|
|
|
cat_name = str(category)[:15] if pd.notna(category) else '(空)'
|
|
cat_name = str(category)[:15] if pd.notna(category) else '(空)'
|
|
|
- cat_uv = int(pivot_uv.loc[category].sum())
|
|
|
|
|
- top3 = ", ".join([f"{ch[:10]}({row[ch]:.0%})" for ch in row.head(3).index])
|
|
|
|
|
- log(f" {cat_name:<17} UV={cat_uv:>8,} → {top3}")
|
|
|
|
|
|
|
+ cat_total_uv = int(pivot_uv.loc[category].sum())
|
|
|
|
|
+ log(f" {cat_name:<17} 总UV={cat_total_uv:>10,}")
|
|
|
|
|
+ for ch in row.head(5).index:
|
|
|
|
|
+ ch_name = ch[:20] if pd.notna(ch) else ''
|
|
|
|
|
+ ch_uv = int(pivot_uv.loc[category, ch]) if ch in pivot_uv.columns else 0
|
|
|
|
|
+ log(f" {ch_name:<20} UV={ch_uv:>8,} 回流率={row[ch]:.1%}")
|
|
|
|
|
+ log()
|
|
|
|
|
|
|
|
log()
|
|
log()
|
|
|
|
|
|