影刀RPA 电商数据分析自动化销售漏斗与用户行为分析作者林焱写在前面电商运营需要每天盯着大量数据流量、转化、GMV、退款率……这些数据散落在各个平台后台手动整合要花两三个小时。影刀可以把这个过程完全自动化定时采集→汇总→分析→生成报告→推送通知全流程无人值守。本文用实际的电商数据分析场景讲清楚怎么建分析模型怎么自动化执行用什么方式呈现结果。拼多多店群自动化上架方案一、电商核心指标体系# 电商分析常用指标定义METRICS{流量指标:[UV独立访客,PV页面浏览量,跳出率,平均停留时长],转化指标:[加购率,下单率,支付率,整体转化率],交易指标:[GMV成交总额,客单价,订单数,件单价],用户指标:[新客率,复购率,留存率,LTV用户终身价值],商品指标:[SKU点击率,SKU转化率,商品退款率],}二、销售漏斗分析importpandasaspdimportmatplotlib matplotlib.use(Agg)importmatplotlib.pyplotaspltimportnumpyasnp plt.rcParams[font.sans-serif][SimHei,Microsoft YaHei]plt.rcParams[axes.unicode_minus]Falsedefcalculate_funnel(df): 计算销售漏斗各阶段转化率 df需包含字段用户ID, 行为类型浏览/加购/下单/支付, 时间 funnel_stages{浏览:visit,加入购物车:add_cart,提交订单:order,完成支付:payment}stage_counts{}forstage_name,action_codeinfunnel_stages.items():countdf[df[行为类型]action_code][用户ID].nunique()stage_counts[stage_name]count# 计算各阶段转化率funnel_data[]stageslist(stage_counts.keys())countslist(stage_counts.values())fori,(stage,count)inenumerate(zip(stages,counts)):overall_ratecount/counts[0]*100# 相对首阶段的转化率ifi0:prev_ratecount/counts[i-1]*100# 相邻阶段转化率else:prev_rate100.0funnel_data.append({阶段:stage,用户数:count,整体转化率:f{overall_rate:.1f}%,逐级转化率:f{prev_rate:.1f}%,流失用户数:counts[i-1]-countifi0else0})returnpd.DataFrame(funnel_data)defplot_funnel(funnel_df,title购买转化漏斗,output_filefunnel.png):绘制漏斗图fig,axplt.subplots(figsize(10,7))stagesfunnel_df[阶段].tolist()countsfunnel_df[用户数].tolist()max_countmax(counts)colors[#1565C0,#1976D2,#1E88E5,#42A5F5]y_positionsrange(len(stages)-1,-1,-1)fori,(stage,count,y_pos,color)inenumerate(zip(stages,counts,y_positions,colors)):# 梯形宽度按用户数比例widthcount/max_count left(1-width)/2# 绘制梯形用填充矩形模拟ax.barh(y_pos,width,leftleft,height0.7,colorcolor,alpha0.85)# 标注rate_strfunnel_df.iloc[i][逐级转化率]ax.text(0.5,y_pos,f{stage}\n{count:,}人 ({rate_str}),hacenter,vacenter,fontsize11,colorwhite,fontweightbold)ax.set_xlim(0,1)ax.set_yticks([])ax.set_xticks([])ax.spines[top].set_visible(False)ax.spines[right].set_visible(False)ax.spines[bottom].set_visible(False)ax.spines[left].set_visible(False)ax.set_title(title,fontsize15,pad15)plt.tight_layout()plt.savefig(output_file,dpi150,bbox_inchestight,facecolorwhite)plt.close()print(f漏斗图已生成{output_file})# 示例数据behavior_datapd.DataFrame({用户ID:list(range(10000)),行为类型:np.random.choice([visit,add_cart,order,payment],10000,p[0.5,0.25,0.15,0.1])})funnel_resultcalculate_funnel(behavior_data)print(funnel_result.to_string(indexFalse))plot_funnel(funnel_result,用户购买转化漏斗分析,purchase_funnel.png)三、用户复购分析defanalyze_repurchase(orders_df): 分析用户复购行为 orders_df: 包含字段 [用户ID, 下单时间, 订单金额] orders_df[下单时间]pd.to_datetime(orders_df[下单时间])orders_dforders_df.sort_values([用户ID,下单时间])# 统计每个用户的购买次数user_order_countsorders_df.groupby(用户ID)[订单金额].agg(购买次数count,总消费sum,首次购买first,# 注意这里first是聚合函数需要用min).reset_index()user_statsorders_df.groupby(用户ID).agg(购买次数(订单金额,count),总消费(订单金额,sum),首次购买(下单时间,min),最后购买(下单时间,max),).reset_index()user_stats[平均客单价]user_stats[总消费]/user_stats[购买次数]# 复购分层user_stats[用户类型]pd.cut(user_stats[购买次数],bins[0,1,2,5,float(inf)],labels[新客1次,回头客2次,高频客3-5次,VIP5次以上])# 各层用户数量和收入贡献segment_analysisuser_stats.groupby(用户类型).agg(用户数(用户ID,count),总收入(总消费,sum),平均客单价(平均客单价,mean)).reset_index()segment_analysis[收入占比]segment_analysis[总收入]/segment_analysis[总收入].sum()*100returnuser_stats,segment_analysisdefplot_repurchase_analysis(segment_df,output_filerepurchase.png):绘制复购分析图fig,axesplt.subplots(1,2,figsize(14,6))# 左图用户数量分布colors[#90CAF9,#42A5F5,#1E88E5,#1565C0]axes[0].pie(segment_df[用户数],labelssegment_df[用户类型],colorscolors,autopct%1.1f%%,startangle90)axes[0].set_title(用户分层占比按购买次数,fontsize13)# 右图收入贡献对比barsaxes[1].bar(segment_df[用户类型],segment_df[收入占比],colorcolors,edgecolorwhite)forbar,valinzip(bars,segment_df[收入占比]):axes[1].text(bar.get_x()bar.get_width()/2,bar.get_height()0.5,f{val:.1f}%,hacenter,fontsize10)axes[1].set_title(各层用户收入贡献率,fontsize13)axes[1].set_xlabel(用户类型)axes[1].set_ylabel(收入占比(%))axes[1].grid(True,axisy,alpha0.3)plt.xticks(rotation15)plt.tight_layout()plt.savefig(output_file,dpi150,bbox_inchestight,facecolorwhite)plt.close()四、商品ABC分析帕累托分析defabc_analysis(products_df,value_col销售额): 商品ABC分析 A类累积销售额前70%的商品 B类累积销售额70%-90%的商品 C类其余商品 products_dfproducts_df.sort_values(value_col,ascendingFalse).reset_index(dropTrue)totalproducts_df[value_col].sum()products_df[销售额占比]products_df[value_col]/total*100products_df[累积占比]products_df[销售额占比].cumsum()defclassify(cumulative):ifcumulative70:returnA类elifcumulative90:returnB类else:returnC类products_df[ABC分类]products_df[累积占比].apply(classify)# 统计各类数量summaryproducts_df.groupby(ABC分类).agg(商品数量(商品名称,count),销售额(销售额,sum),).reset_index()summary[商品占比]summary[商品数量]/len(products_df)*100summary[销售额占比]summary[销售额]/total*100print(\n ABC分析结果 )print(summary.to_string(indexFalse))print(f\nA类商品占商品{summary.loc[summary[ABC分类]A类,商品占比].values[0]:.1f}%贡献销售额{summary.loc[summary[ABC分类]A类,销售额占比].values[0]:.1f}%)returnproducts_df,summary五、自动化执行与推送TEMU店群如何管理运营importdatetimedefdaily_ecommerce_report():每日电商数据分析自动报告todaydatetime.date.today()yesterdaytoday-datetime.timedelta(days1)# 1. 从数据库或Excel读取昨天的数据orders_dfpd.read_excel(forders_{yesterday.isoformat()}.xlsx)behavior_dfpd.read_excel(fbehavior_{yesterday.isoformat()}.xlsx)products_dfpd.read_excel(fproducts_{yesterday.isoformat()}.xlsx)# 2. 执行各类分析funnel_resultcalculate_funnel(behavior_df)user_stats,segment_dfanalyze_repurchase(orders_df)products_result,abc_summaryabc_analysis(products_df)# 3. 生成图表plot_funnel(funnel_result,f{yesterday}转化漏斗,daily_funnel.png)plot_repurchase_analysis(segment_df,daily_repurchase.png)# 4. 汇总核心指标total_gmvorders_df[订单金额].sum()order_countlen(orders_df)avg_ordertotal_gmv/order_countiforder_countelse0repurchase_rate(user_stats[购买次数]1).mean()*100report_textf {yesterday}电商数据日报 核心指标 • GMV{total_gmv/10000:.1f}万元 • 订单数{order_count}笔 • 客单价{avg_order:.0f}元 • 复购率{repurchase_rate:.1f}% 转化漏斗{funnel_result[[阶段,用户数,逐级转化率]].to_string(indexFalse)} 商品ABC分析{abc_summary.to_string(indexFalse)}print(report_text)# 5. 发送报告通过企业微信机器人importrequests ROBOT_WEBHOOKhttps://qyapi.weixin.qq.com/cgi-bin/webhook/send?key你的keyrequests.post(ROBOT_WEBHOOK,json{msgtype:markdown,markdown:{content:report_text}})print(f日报已推送完成{yesterday})# 在影刀中设置定时任务每天早上8:30自动执行daily_ecommerce_report()六、踩坑记录坑1各平台数据口径不一致天猫、京东、自建商城的GMV计算口径不同含税/不含税、是否含取消订单在汇总前要统一口径不能直接相加。坑2日期时区问题电商平台数据一般用UTC8但从API拿到的时间戳有时是UTC。转换pd.to_datetime(df[时间], units).dt.tz_localize(UTC).dt.tz_convert(Asia/Shanghai)。坑3数据延迟很多电商平台的数据有T1延迟当天的完整数据要次日才能查到。自动化脚本要查昨天的数据不要查今天的今天数据不完整。坑4退款订单的处理GMV分析要区分交易成功和已退款订单。直接用所有订单的金额汇总会高估GMV需要减去退款金额才是实际GMV。总结电商数据分析自动化的价值把每天两三小时的手动整理变成5分钟的自动化脚本。核心分析模型漏斗转化效率、复购用户价值、ABC商品聚焦。搭好这三个模型90%的电商日常分析需求都能覆盖。署名林焱