Files
ObsidianHome/百家/analyze_xlsx2.py
T

83 lines
3.8 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""单篇数据深度分析:按批次看转化率、标题特征、存量增长"""
import sys
import pandas as pd
sys.stdout.reconfigure(encoding="utf-8")
df = pd.read_excel(r"E:\Download\单篇数据.xlsx", sheet_name="data")
df.columns = [str(c).strip() for c in df.columns]
df["阅读量"] = pd.to_numeric(df["阅读量"], errors="coerce").fillna(0)
df["推荐量"] = pd.to_numeric(df["推荐量"], errors="coerce").fillna(0)
df["点赞量"] = pd.to_numeric(df["点赞量"], errors="coerce").fillna(0)
df["评论量"] = pd.to_numeric(df["评论量"], errors="coerce").fillna(0)
df["分享量"] = pd.to_numeric(df["分享量"], errors="coerce").fillna(0)
df["收藏量"] = pd.to_numeric(df["收藏量"], errors="coerce").fillna(0)
df["转化率"] = (df["阅读量"] / df["推荐量"].clip(lower=1)).round(3)
df["点赞率%"] = (df["点赞量"] / df["阅读量"].clip(lower=1) * 100).round(2)
print("=" * 100)
print("【一】按发布批次看转化率(核心指标)")
print("=" * 100)
g = df.groupby("发布时间").agg(
条数=("标题", "count"),
总阅读=("阅读量", "sum"),
总推荐=("推荐量", "sum"),
条均阅读=("阅读量", "mean"),
).round(0)
g["批次转化率"] = (g["总阅读"] / g["总推荐"].clip(lower=1)).round(3)
print(g.to_string())
print()
print("=" * 100)
print("【二】11-06 批次明细(13条,条均440)")
print("=" * 100)
b1106 = df[df["发布时间"] == "2026-11-06"].sort_values("阅读量", ascending=False)
for _, r in b1106.iterrows():
print(f" 阅读{r['阅读量']:>6.0f} 推荐{r['推荐量']:>6.0f} 转化{r['转化率']:>5.2f} | {r['标题'][:44]}")
print()
print("=" * 100)
print("【三】转化率排行(全部41条)")
print("=" * 100)
print("--- 转化率 TOP 12(推荐没白给)---")
for _, r in df.nlargest(12, "转化率").iterrows():
print(f" {r['转化率']:>5.2f} | 阅读{r['阅读量']:>6.0f} | {r['发布时间']} | {r['标题'][:42]}")
print()
print("--- 转化率 BOTTOM 12(给了推荐没人点)---")
for _, r in df.nsmallest(12, "转化率").iterrows():
print(f" {r['转化率']:>5.2f} | 阅读{r['阅读量']:>6.0f} | 推荐{r['推荐量']:>5.0f} | {r['标题'][:42]}")
print()
print("=" * 100)
print("【四】标题写法与转化率(关键归因)")
print("=" * 100)
patterns = {
"抽象黑话(降维打击/教科书级/防线/智商碾压/拉扯)": ["降维打击", "教科书级", "立体防线", "智商碾压", "拉扯", "助攻"],
"具体动作(炸毛/冲锋/重踏/顶翻/甩掉/逼退)": ["炸毛", "冲锋", "重踏", "顶翻", "甩掉", "逼退", "一记", "蹬"],
"警告式开头(千万别惹/为什么)": ["千万别", "为什么", "连狮子都"],
"含实拍/抓拍(违规)": ["实拍", "抓拍"],
}
for name, kws in patterns.items():
m = df[df["标题"].apply(lambda t: any(k in t for k in kws))]
if len(m):
print(f" {name}: {len(m)}条, 条均阅读 {m['阅读量'].mean():.0f}, 批次转化率 {(m['阅读量'].sum()/m['推荐量'].clip(lower=1).sum()):.2f}")
print()
print("=" * 100)
print("【五】存量增长:对比 11-05 那次导出")
print("=" * 100)
prev = {
"悬崖冰桥上的极限遭遇战": 15571, "绝地反击!大角羊引发落石": 12628,
"千万别惹看家大鹅": 7781, "黄鼠狼进院偷袭小鸡,老母鸡瞬间炸毛暴起,实力演绎": 11548,
"为什么连鳄鱼都不敢惹河马": 4051, "高空猛禽突然掠过": 5226,
"大角羊被狼群逼入绝境,竟靠这一招": 5439,
}
for kw, old in prev.items():
hit = df[df["标题"].str.contains(kw[:12], regex=False)]
if len(hit):
new = hit.iloc[0]["阅读量"]
growth = (new - old) / old * 100 if old else 0
print(f" {hit.iloc[0]['标题'][:30]:<32} {old:>6.0f} → {new:>6.0f} (+{growth:.0f}%)")