{"id":4050,"date":"2025-10-12T19:41:19","date_gmt":"2025-10-12T11:41:19","guid":{"rendered":"http:\/\/viplao.com\/?p=4050"},"modified":"2025-10-12T19:41:21","modified_gmt":"2025-10-12T11:41:21","slug":"%e3%80%90python%e5%ae%9e%e8%b7%b5%e6%a1%88%e4%be%8b%e3%80%91%e6%96%b0%e7%94%a8%e6%88%b7%e8%bd%ac%e5%8c%96%e6%bc%8f%e6%96%97%e5%88%86%e6%9e%90%e4%b8%8e%e4%bc%98%e5%8c%96","status":"publish","type":"post","link":"http:\/\/viplao.com\/index.php\/2025\/10\/12\/%e3%80%90python%e5%ae%9e%e8%b7%b5%e6%a1%88%e4%be%8b%e3%80%91%e6%96%b0%e7%94%a8%e6%88%b7%e8%bd%ac%e5%8c%96%e6%bc%8f%e6%96%97%e5%88%86%e6%9e%90%e4%b8%8e%e4%bc%98%e5%8c%96\/","title":{"rendered":"\u3010PYTHON\u5b9e\u8df5\u6848\u4f8b\u3011\u65b0\u7528\u6237\u8f6c\u5316\u6f0f\u6597\u5206\u6790\u4e0e\u4f18\u5316"},"content":{"rendered":"\n<ul>\n<li><strong>\u4e1a\u52a1\u75db\u70b9\uff1a<\/strong>&nbsp;\u201c\u6211\u82b1\u4e86\u5f88\u591a\u94b1\u4e70\u6765\u4e86\u6d41\u91cf\uff0c\u7528\u6237\u4e5f\u8bbf\u95ee\u4e86\u6211\u7684\u7f51\u7ad9\/APP\uff0c\u4f46\u4e3a\u4ec0\u4e48\u6700\u540e\u4e0b\u5355\u7684\u4eba\u8fd9\u4e48\u5c11\uff1f\u7528\u6237\u5230\u5e95\u5728\u54ea\u4e00\u6b65\u8dd1\u6389\u4e86\uff1f\u201d<\/li>\n\n\n\n<li><strong>\u6838\u5fc3\u6982\u5ff5\uff1a<\/strong>\n<ul>\n<li><strong>\u8f6c\u5316\u6f0f\u6597 (Conversion Funnel):<\/strong>&nbsp;\u8fd9\u662f\u4e00\u4e2a\u53ef\u89c6\u5316\u6a21\u578b\uff0c\u7528\u6765\u63cf\u8ff0\u7528\u6237\u4ece\u8fdb\u5165\u5e73\u53f0\u5230\u5b8c\u6210\u6700\u7ec8\u76ee\u6807\uff08\u5982\u4e0b\u5355\u652f\u4ed8\uff09\u6240\u7ecf\u5386\u7684\u5173\u952e\u6b65\u9aa4\u3002\u5b83\u5f62\u5982\u6f0f\u6597\uff0c\u4e0a\u5bbd\u4e0b\u7a84\uff0c\u56e0\u4e3a\u6bcf\u4e00\u6b65\u90fd\u4f1a\u6709\u7528\u6237\u6d41\u5931\u3002<\/li>\n\n\n\n<li><strong>\u5173\u952e\u6b65\u9aa4\uff1a<\/strong>&nbsp;\u7535\u5546\u4e2d\u5178\u578b\u7684\u6f0f\u6597\u5305\u62ec\uff1a<code>\u6d4f\u89c8\u5546\u54c1<\/code>&nbsp;-&gt;&nbsp;<code>\u52a0\u5165\u8d2d\u7269\u8f66<\/code>&nbsp;-&gt;&nbsp;<code>\u63d0\u4ea4\u8ba2\u5355<\/code>&nbsp;-&gt;&nbsp;<code>\u652f\u4ed8\u6210\u529f<\/code>\u3002<\/li>\n\n\n\n<li><strong>\u8f6c\u5316\u7387\uff1a<\/strong>&nbsp;<code>(\u4e0b\u4e00\u6b65\u7528\u6237\u6570 \/ \u4e0a\u4e00\u6b65\u7528\u6237\u6570) \u00d7 100%<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>\u5206\u6790\u601d\u8def\uff1a<\/strong>\n<ol>\n<li><strong>\u5b9a\u4e49\u6f0f\u6597\uff1a<\/strong>&nbsp;\u660e\u786e\u5206\u6790\u7684\u4e1a\u52a1\u6d41\u7a0b\u548c\u5173\u952e\u6b65\u9aa4\u3002<\/li>\n\n\n\n<li><strong>\u6570\u636e\u63d0\u53d6\uff1a<\/strong>&nbsp;\u4ece\u7528\u6237\u884c\u4e3a\u65e5\u5fd7\uff08\u57cb\u70b9\u6570\u636e\uff09\u4e2d\uff0c\u63d0\u53d6\u6bcf\u4e2a\u6b65\u9aa4\u7684\u72ec\u7acb\u7528\u6237\u6570\uff08UV\uff09\u3002<\/li>\n\n\n\n<li><strong>\u8ba1\u7b97\u8f6c\u5316\u7387\uff1a<\/strong>&nbsp;\u8ba1\u7b97\u6bcf\u4e00\u6b65\u76f8\u5bf9\u4e8e\u4e0a\u4e00\u6b65\u7684\u8f6c\u5316\u7387\uff0c\u4ee5\u53ca\u76f8\u5bf9\u4e8e\u7b2c\u4e00\u6b65\u7684\u603b\u8f6c\u5316\u7387\u3002<\/li>\n\n\n\n<li><strong>\u5b9a\u4f4d\u74f6\u9888\uff1a<\/strong>&nbsp;\u627e\u51fa\u8f6c\u5316\u7387<strong>\u9aa4\u964d<\/strong>\u7684\u73af\u8282\uff0c\u8fd9\u5c31\u662f\u8f6c\u5316\u6f0f\u6597\u7684\u201c\u74f6\u9888\u201d\uff0c\u662f\u8fd0\u8425\u4f18\u5316\u7684\u91cd\u70b9\u3002<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u5b9e\u8df5\u6848\u4f8b\uff1a\u5206\u6790APP\u9996\u9875\u5230\u652f\u4ed8\u6210\u529f\u7684\u7528\u6237\u8f6c\u5316\u6f0f\u6597<\/strong><\/h4>\n\n\n\n<p>python\u590d\u5236<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import pandas as pd\nimport plotly.graph_objects as go\n\n# --- 1. \u6570\u636e\u51c6\u5907 ---\n# \u6a21\u62df\u4e00\u4efd\u7528\u6237\u884c\u4e3a\u65e5\u5fd7\u6570\u636e\n# \u6bcf\u4e00\u884c\u4ee3\u8868\u4e00\u4e2a\u7528\u6237\u5728\u4e00\u4e2a\u65f6\u95f4\u70b9\u4ea7\u751f\u7684\u4e00\u4e2a\u884c\u4e3a\nlog_data = {\n    'user_id': &#91;1, 2, 1, 3, 2, 1, 4, 5, 2, 3, 1, 5, 4, 3],\n    'event_name': &#91;\n        'app_launch', 'app_launch', 'view_product', 'app_launch', 'view_product',\n        'add_to_cart', 'app_launch', 'app_launch', 'add_to_cart', 'view_product',\n        'checkout', 'view_product', 'view_product', 'add_to_cart'\n    ]\n}\nlog_df = pd.DataFrame(log_data)\n\nprint(\"--- \u539f\u59cb\u884c\u4e3a\u65e5\u5fd7 ---\")\nprint(log_df.head())\n\n# --- 2. \u5b9a\u4e49\u6f0f\u6597\u6b65\u9aa4\u5e76\u8ba1\u7b97\u6bcf\u6b65\u7528\u6237\u6570 ---\n# \u5b9a\u4e49\u6f0f\u6597\u7684\u987a\u5e8f\nfunnel_steps = &#91;'app_launch', 'view_product', 'add_to_cart', 'checkout']\n\n# \u8ba1\u7b97\u6bcf\u4e2a\u6b65\u9aa4\u7684\u72ec\u7acb\u7528\u6237\u6570 (UV)\nstep_uv = log_df.groupby('event_name')&#91;'user_id'].nunique().reindex(funnel_steps).reset_index()\nstep_uv.columns = &#91;'step', 'user_count']\n\nprint(\"\\n--- \u5404\u6b65\u9aa4\u72ec\u7acb\u7528\u6237\u6570(UV) ---\")\nprint(step_uv)\n\n# --- 3. \u7ed8\u5236\u8f6c\u5316\u6f0f\u6597\u56fe ---\nfig = go.Figure(go.Funnel(\n    y = step_uv&#91;'step'],\n    x = step_uv&#91;'user_count'],\n    textinfo = \"value+percent initial+percent previous\", # \u663e\u793a\uff1a\u6570\u503c+\u76f8\u5bf9\u7b2c\u4e00\u6b65\u8f6c\u5316\u7387+\u76f8\u5bf9\u4e0a\u4e00\u6b65\u8f6c\u5316\u7387\n    marker = {\"color\": &#91;\"#0099cc\", \"#33a6d6\", \"#66b3e0\", \"#99c0eb\"]}\n))\n\nfig.update_layout(\n    title={\n        'text': \"\u7528\u6237\u8f6c\u5316\u6f0f\u6597\u5206\u6790\",\n        'y':0.9,\n        'x':0.5,\n        'xanchor': 'center',\n        'yanchor': 'top'\n    }\n)\n\n# \u5728Jupyter\u4e2d\uff0c\u8fd9\u884c\u4ee3\u7801\u4f1a\u76f4\u63a5\u663e\u793a\u4ea4\u4e92\u5f0f\u56fe\u8868\nfig.show()\n\n# --- 4. \u4e1a\u52a1\u7ed3\u8bba ---\nprint(\"\\n--- \u5206\u6790\u7ed3\u8bba ---\")\nprint(\"1. \u4ece`app_launch`\u5230`view_product`\uff0c80%\u7684\u7528\u6237\u7559\u5b58\uff0c\u8bf4\u660e\u9996\u9875\u5185\u5bb9\u5bf9\u5927\u90e8\u5206\u7528\u6237\u6709\u5438\u5f15\u529b\u3002\")\nprint(\"2. \u4ece`view_product`\u5230`add_to_cart`\uff0c\u8f6c\u5316\u7387\u4e3a75%\uff0c\u8868\u73b0\u5c1a\u53ef\u3002\")\nprint(\"3. **\u74f6\u9888\u53d1\u73b0**\uff1a\u4ece`add_to_cart`\u5230`checkout`\uff0c\u8f6c\u5316\u7387\u9aa4\u964d\u81f333.3%\uff01\u8fd9\u662f\u6700\u5927\u7684\u6d41\u5931\u70b9\u3002\")\nprint(\"4. **\u4f18\u5316\u5efa\u8bae**\uff1a\u5e94\u91cd\u70b9\u5206\u6790\u8d2d\u7269\u8f66\u5230\u7ed3\u7b97\u9875\u7684\u6d41\u7a0b\u3002\u53ef\u80fd\u539f\u56e0\uff1a\u7ed3\u7b97\u6309\u94ae\u4e0d\u660e\u663e\uff1f\u9700\u8981\u5f3a\u5236\u767b\u5f55\uff1f\u8fd0\u8d39\u8fc7\u9ad8\uff1f\u652f\u4ed8\u65b9\u5f0f\u592a\u5c11\uff1f\u53ef\u4ee5\u9488\u5bf9\u8fd9\u4e9b\u5047\u8bbe\u8bbe\u8ba1A\/B\u6d4b\u8bd5\u8fdb\u884c\u4f18\u5316\u3002\")\n<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" loading=\"lazy\" width=\"1024\" height=\"656\" src=\"http:\/\/viplao.com\/wp-content\/uploads\/2025\/10\/image-4-1024x656.png\" alt=\"\" class=\"wp-image-4051\" srcset=\"http:\/\/viplao.com\/wp-content\/uploads\/2025\/10\/image-4-1024x656.png 1024w, http:\/\/viplao.com\/wp-content\/uploads\/2025\/10\/image-4-300x192.png 300w, http:\/\/viplao.com\/wp-content\/uploads\/2025\/10\/image-4-768x492.png 768w, http:\/\/viplao.com\/wp-content\/uploads\/2025\/10\/image-4-1536x985.png 1536w, http:\/\/viplao.com\/wp-content\/uploads\/2025\/10\/image-4-468x300.png 468w, http:\/\/viplao.com\/wp-content\/uploads\/2025\/10\/image-4.png 1638w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9e\u8df5\u6848\u4f8b\uff1a\u5206\u6790APP\u9996\u9875\u5230\u652f\u4ed8\u6210\u529f\u7684\u7528\u6237\u8f6c\u5316\u6f0f\u6597 python\u590d\u5236<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[28],"views":530,"_links":{"self":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/4050"}],"collection":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/comments?post=4050"}],"version-history":[{"count":1,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/4050\/revisions"}],"predecessor-version":[{"id":4052,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/posts\/4050\/revisions\/4052"}],"wp:attachment":[{"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/media?parent=4050"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/categories?post=4050"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/viplao.com\/index.php\/wp-json\/wp\/v2\/tags?post=4050"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}