{"id":117371,"date":"2026-10-24T17:48:39","date_gmt":"2026-10-24T09:48:39","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/117371.html"},"modified":"2026-10-24T17:48:39","modified_gmt":"2026-10-24T09:48:39","slug":"python-polars-%e9%ab%98%e6%80%a7%e8%83%bd%e6%95%b0%e6%8d%ae%e5%a4%84%e7%90%86%e5%bc%95%e6%93%8e%e6%b7%b1%e5%ba%a6%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/117371.html","title":{"rendered":"Python Polars \u9ad8\u6027\u80fd\u6570\u636e\u5904\u7406\u5f15\u64ce\u6df1\u5ea6\u89e3\u6790"},"content":{"rendered":"<h2 id=\"python-polars-\u9ad8\u6027\u80fd\u6570\u636e\u5904\u7406\u5f15\u64ce\u6df1\u5ea6\u89e3\u6790\">1. \u80cc\u666f&#xff1a;\u4e3a\u4ec0\u4e48\u5728Pandas \u5df2\u7ecf\u5f88\u597d\u7528\u7684\u5e74\u4ee3\u8fd8\u8981\u5b66 Polars<\/h2>\n<h4 id=\"11-\u6570\u636e\u5de5\u7a0b\u5e08\u7684\u4e09\u6b21\u89c9\u9192\">1.1 \u6570\u636e\u5de5\u7a0b\u5e08\u7684\u4e09\u6b21\u89c9\u9192<\/h4>\n<p>\u505a\u5de5\u4e1a\u6570\u91c7\u7684\u4eba\u90fd\u4f1a\u7ecf\u5386\u4e09\u4e2a\u9636\u6bb5&#xff1a;<\/p>\n<li>\u7b2c\u4e00\u9636\u6bb5&#xff1a;\u6570\u636e\u91cf\u5c0f&#xff0c;pd.read_csv()\u00a0\u4e00\u628a\u68ad&#xff0c;\u51e0\u767e MB \u7684 CSV \u4e5f\u5c31\u7b49\u51e0\u79d2\u3002<\/li>\n<li>\u7b2c\u4e8c\u9636\u6bb5&#xff1a;\u70b9\u4f4d\u660e\u7ec6\u8d8a\u6512\u8d8a\u591a\u2014\u2014\u4e00\u53f0 CNC \u6bcf\u79d2 10 \u4e2a\u70b9\u4f4d\u3001200 \u53f0\u8bbe\u5907\u300124 \u5c0f\u65f6\u4e0d\u505c\u673a&#xff0c;\u4e00\u5929\u5c31\u662f\u00a01.7 \u4ebf\u884c\u3002Pandas \u5f00\u59cb\u5185\u5b58\u66b4\u6da8\u3001\u5361\u987f\u3001\u8b66\u544a\u5237\u5c4f&#xff0c;concat\u00a0\u4e00\u6b21\u8981\u7b49\u534a\u5206\u949f\u3002<\/li>\n<li>\u7b2c\u4e09\u9636\u6bb5&#xff1a;\u4f60\u53d1\u73b0 Pandas \u6162\u4e0d\u662f\u56e0\u4e3a\u5b83\u61d2&#xff0c;\u800c\u662f\u5b83\u7684\u8bbe\u8ba1\u54f2\u5b66\u51b3\u5b9a\u4e86\u5b83\u5728\u5927\u6570\u636e\u91cf\u4e0a\u7684\u5929\u82b1\u677f&#xff1a;\n<ul>\n<li>\u884c\u5f0f\u5185\u5b58\u5e03\u5c40&#xff1a;\u6309\u8bb0\u5f55\u8fde\u7eed\u5b58\u50a8&#xff0c;\u8bfb\u53d6\u4e00\u5217\u8981\u8de8\u8fc7\u6574\u884c\u6240\u6709\u5b57\u6bb5&#xff0c;CPU \u7f13\u5b58\u5229\u7528\u7387\u4f4e&#xff1b;<\/li>\n<li>\u5355\u7ebf\u7a0b\u6267\u884c&#xff1a;\u73b0\u4ee3 CPU 8 \u6838 16 \u7ebf\u7a0b\u6446\u5728\u90a3\u91cc&#xff0c;Pandas \u53ea\u7528\u4e00\u4e2a\u6838&#xff1b;<\/li>\n<li>\u6025\u5207\u6267\u884c&#xff1a;\u6bcf\u5199\u4e00\u884c\u4ee3\u7801\u5c31\u7acb\u523b\u7b97\u5b8c&#xff0c;\u4e2d\u95f4\u4ea7\u751f\u5927\u91cf\u4e34\u65f6 DataFrame&#xff0c;\u5185\u5b58\u5cf0\u503c\u5931\u63a7&#xff1b;<\/li>\n<li>\u51fd\u6570\u540d\u6df7\u4e71&#xff1a;df[df[&#039;a&#039;]&gt;1]\u3001df.query()\u3001df.loc[&#8230;]\u3001df.filter()\u2026\u2026\u540c\u4e00\u4e2a\u64cd\u4f5c\u6709\u56db\u4e94\u79cd\u5199\u6cd5&#xff0c;\u53ef\u8bfb\u6027\u707e\u96be\u3002<\/li>\n<\/ul>\n<\/li>\n<h4 id=\"12-polars-\u662f\u4ec0\u4e48\">1.2 Polars \u662f\u4ec0\u4e48<\/h4>\n<p>Polars \u662f 2020 \u5e74\u8d77\u7531 Ritchie Vink \u53d1\u8d77\u3001\u7528\u00a0Rust\u00a0\u7f16\u5199\u7684\u5f00\u6e90 DataFrame \u5e93&#xff08;MIT \u534f\u8bae&#xff09;\u3002\u5b83\u7684\u6838\u5fc3\u627f\u8bfa\u662f&#xff1a;<\/p>\n<table>\n<tbody>\n<tr>\u627f\u8bfa\u5b9e\u73b0\u65b9\u5f0f<\/tr>\n<tr>\n<td>\u5feb<\/td>\n<td>\u5217\u5f0f\u5b58\u50a8&#xff08;Apache Arrow \u5185\u5b58\u683c\u5f0f&#xff09;&#043; SIMD \u5411\u91cf\u5316 &#043; \u591a\u7ebf\u7a0b\u5e76\u884c<\/td>\n<\/tr>\n<tr>\n<td>\u7701<\/td>\n<td>\u60f0\u6027\u6267\u884c&#xff08;LazyFrame&#xff09;\u6574\u68f5\u67e5\u8be2\u6811\u4f18\u5316\u540e\u518d\u6267\u884c&#xff0c;\u65e0\u4e2d\u95f4\u4e34\u65f6\u5e27<\/td>\n<\/tr>\n<tr>\n<td>\u7a33<\/td>\n<td>\u7c7b\u578b\u4e25\u683c&#xff08;\u533a\u5206 Int32\/Int64\/Float32\/Float64&#xff09;&#xff0c;\u62d2\u7edd\u300c\u9759\u9ed8\u9690\u5f0f\u8f6c\u6362\u300d<\/td>\n<\/tr>\n<tr>\n<td>\u723d<\/td>\n<td>\u7edf\u4e00\u8868\u8fbe\u5f0f API&#xff0c;\u4e00\u4e2a\u00a0.expr()\u00a0\u8bed\u6cd5\u8d2f\u7a7f\u9009\u62e9\u3001\u8fc7\u6ee4\u3001\u805a\u5408\u3001\u7a97\u53e3<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u5b83\u4e0e Pandas \u4e0d\u662f\u66ff\u4ee3\u4e0e\u88ab\u66ff\u4ee3&#xff0c;\u800c\u662f\u00a0\u901a\u7528\u5206\u6790\u5de5\u5177 vs \u9ad8\u6027\u80fd\u5f15\u64ce\u7684\u5206\u5c42\u5173\u7cfb&#xff1a;<\/p>\n<table>\n<tbody>\n<tr>\u7ef4\u5ea6PandasPolars<\/tr>\n<tr>\n<td>\u5185\u5b58\u5e03\u5c40<\/td>\n<td>\u884c\u5f0f&#xff08;BlockManager&#xff09;<\/td>\n<td>\u5217\u5f0f&#xff08;Arrow&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u6267\u884c\u6a21\u578b<\/td>\n<td>\u6025\u5207&#xff08;Eager&#xff09;<\/td>\n<td>\u6025\u5207 &#043; \u60f0\u6027&#xff08;Lazy&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u5e76\u884c<\/td>\n<td>\u5355\u7ebf\u7a0b\u4e3a\u4e3b<\/td>\n<td>\u591a\u7ebf\u7a0b&#xff08;\u9ed8\u8ba4\u5168\u90e8\u6838\u5fc3&#xff09;<\/td>\n<\/tr>\n<tr>\n<td>\u7c7b\u578b\u7cfb\u7edf<\/td>\n<td>\u5bbd\u677e&#xff0c;\u9690\u5f0f\u8f6c\u6362<\/td>\n<td>\u4e25\u683c&#xff0c;\u7c7b\u578b\u654f\u611f<\/td>\n<\/tr>\n<tr>\n<td>\u8868\u8fbe\u5f0f<\/td>\n<td>\u65b9\u6cd5\u5206\u6563\u3001\u5199\u6cd5\u591a<\/td>\n<td>\u7edf\u4e00\u8868\u8fbe\u5f0f\u4f53\u7cfb<\/td>\n<\/tr>\n<tr>\n<td>\u9002\u7528<\/td>\n<td>\u63a2\u7d22\u6027\u5206\u6790\u3001\u673a\u5668\u5b66\u4e60\u7279\u5f81\u5de5\u7a0b\u3001\u751f\u6001\u4f9d\u8d56<\/td>\n<td>\u5927\u6279\u91cf\u6570\u636e\u6e05\u6d17\u3001ETL\u3001\u62a5\u8868\u805a\u5408\u3001\u6d41\u5f0f\u5904\u7406<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3 id=\"2-\u6838\u5fc3\u6982\u5ff5\u901f\u89c8\">2. \u6838\u5fc3\u6982\u5ff5\u901f\u89c8<\/h3>\n<p>\u5148\u5efa\u7acb Polars \u7684\u4e16\u754c\u89c2&#xff0c;\u5b83\u53ea\u6709\u51e0\u4e2a\u5173\u952e\u6982\u5ff5&#xff0c;\u4f46\u6bcf\u4e2a\u90fd\u6bd4 Pandas \u66f4\u8f83\u771f\u3002<\/p>\n<h4 id=\"21-dataframe-\u4e0e-series\u548c-pandas-\u540c\u540d\u4f46\u4e0d\u540c\u5185\u6838\">2.1 DataFrame \u4e0e Series&#xff08;\u548c Pandas \u540c\u540d\u4f46\u4e0d\u540c\u5185\u6838&#xff09;<\/h4>\n<ul>\n<li>pl.DataFrame&#xff1a;\u4e8c\u7ef4\u8868&#xff0c;\u5e95\u5c42\u662f\u00a0Arrow \u5217\u5f0f\u5b58\u50a8&#xff0c;\u6bcf\u4e00\u5217\u662f\u4e00\u4e2a\u8fde\u7eed\u5185\u5b58\u6570\u7ec4&#xff0c;\u7c7b\u578b\u4e00\u81f4&#xff1b;<\/li>\n<li>pl.Series&#xff1a;\u5355\u5217&#xff0c;\u672c\u8d28\u662f\u6307\u5411 Arrow ChunkedArray \u7684\u53e5\u67c4&#xff1b;<\/li>\n<li>\u5217\u7684\u7c7b\u578b\u6709\u4e25\u683c\u8bed\u4e49&#xff1a;Int8\/16\/32\/64\u3001UInt*\u3001Float32\/64\u3001String\u3001Boolean\u3001Date\/Datetime\/Duration\u3001List\u3001Struct\u3001Categorical\u3001Enum\u3002<\/li>\n<\/ul>\n<h4 id=\"22-\u8868\u8fbe\u5f0fexpressionpolars-\u7684\u7075\u9b42\">2.2 \u8868\u8fbe\u5f0f&#xff08;Expression&#xff09;&#xff1a;Polars \u7684\u7075\u9b42<\/h4>\n<p>Pandas \u7684 API \u662f\u65b9\u6cd5\u4f5c\u7528\u5728 DataFrame \u4e0a&#xff1b;Polars \u7684 API \u662f\u00a0\u8868\u8fbe\u5f0f\u4f5c\u7528\u5728\u5217\u4e0a&#xff0c;\u518d\u4f20\u7ed9\u4e0a\u4e0b\u6587\u3002<\/p>\n<p># Pandas \u98ce\u683c&#xff1a;\u65b9\u6cd5\u5206\u6563<br \/>\ndf[df[&#039;ts&#039;].dt.hour &#061;&#061; 8][&#039;value&#039;].mean()<\/p>\n<p># Polars \u98ce\u683c&#xff1a;\u8868\u8fbe\u5f0f\u7edf\u4e00<br \/>\ndf.filter(pl.col(&#039;ts&#039;).dt.hour() &#061;&#061; 8).select(pl.col(&#039;value&#039;).mean())<\/p>\n<p>\u8868\u8fbe\u5f0f\u53ef\u4ee5\u7ec4\u5408\u3001\u590d\u7528\u3001\u5e76\u884c\u6c42\u503c\u3002\u4e00\u4e2a\u8868\u8fbe\u5f0f\u5bf9\u8c61\u53ef\u4ee5\u5728\u591a\u4e2a\u4e0a\u4e0b\u6587\u91cc\u7528&#xff1a;select&#xff08;\u9009\u5217&#xff09;\u3001filter&#xff08;\u8fc7\u6ee4&#xff09;\u3001with_columns&#xff08;\u65b0\u589e\u5217&#xff09;\u3001group_by&#xff08;\u5206\u7ec4\u805a\u5408&#xff09;\u3001sort&#xff08;\u6392\u5e8f&#xff09;\u3002<\/p>\n<h4 id=\"23-eager-\u4e0e-lazy-\u53cc\u6a21\u5f0f\">2.3 Eager \u4e0e Lazy \u53cc\u6a21\u5f0f<\/h4>\n<ul>\n<li>Eager&#xff1a;.collect()\u00a0\u524d\u7684 DataFrame \u64cd\u4f5c&#xff0c;\u6bcf\u6b65\u7acb\u523b\u6267\u884c&#xff1b;<\/li>\n<li>Lazy&#xff1a;.lazy()\u00a0\u751f\u6210 LazyFrame&#xff0c;\u53ea\u8bb0\u5f55\u67e5\u8be2\u8ba1\u5212&#xff0c;\u6700\u7ec8\u00a0.collect()\u00a0\u624d\u6267\u884c\u3002\u4e2d\u95f4\u4e0d\u4f1a\u4ea7\u751f\u4efb\u4f55\u4e34\u65f6\u5e27&#xff0c;\u4e14\u4f1a\u89e6\u53d1\u67e5\u8be2\u4f18\u5316\u5668\u3002<\/li>\n<\/ul>\n<p>\u8fd9\u662f Polars \u6027\u80fd\u795e\u8bdd\u7684\u6838\u5fc3\u4e4b\u4e00&#xff1a;lazy\u00a0\u6a21\u5f0f\u4f1a\u628a\u4f60\u7684\u6574\u6761\u6d41\u6c34\u7ebf&#xff08;\u8bfb\u6587\u4ef6 \u2192 \u8fc7\u6ee4 \u2192 \u805a\u5408 \u2192 \u6392\u5e8f&#xff09;\u5408\u5e76\u4f18\u5316\u540e\u518d\u6267\u884c&#xff0c;\u800c\u4e0d\u662f\u50cf Pandas \u4e00\u6837\u6bcf\u4e00\u6b65\u5efa\u4e00\u4e2a\u4e34\u65f6\u8868\u3002<\/p>\n<h4 id=\"24-\u5217\u5f0f\u5b58\u50a8\u4e3a\u4ec0\u4e48\u5feb\">2.4 \u5217\u5f0f\u5b58\u50a8\u4e3a\u4ec0\u4e48\u5feb<\/h4>\n<p>\u6570\u636e\u5728\u5185\u5b58\u4e2d\u662f\u6309\u5217\u8fde\u7eed\u5b58\u653e\u7684\u3002\u8fd9\u610f\u5473\u7740&#xff1a;<\/p>\n<ul>\n<li>\u8bfb\u53d6\u4e00\u5217 &#061; \u987a\u5e8f\u626b\u63cf\u4e00\u6bb5\u8fde\u7eed\u5185\u5b58&#xff0c;CPU \u7f13\u5b58\u547d\u4e2d\u7387\u9ad8&#xff1b;<\/li>\n<li>\u8fc7\u6ee4\u4e00\u5217\u65f6&#xff0c;\u5176\u4ed6\u5217\u5b8c\u5168\u4e0d\u78b0&#xff08;Pandas \u884c\u5f0f\u5b58\u50a8\u8981\u6574\u884c\u8bfb\u51fa\u518d\u4e22\u5f03&#xff09;&#xff1b;<\/li>\n<li>\u6570\u503c\u8ba1\u7b97\u5929\u7136\u5411\u91cf\u5316&#xff08;\u4e00\u5217\u6570\u636e\u5c31\u662f\u4e00\u7247\u540c\u7c7b\u578b\u6570\u7ec4&#xff0c;\u53ef\u4ee5\u76f4\u63a5\u4e0a SIMD&#xff09;&#xff1b;<\/li>\n<li>\u538b\u7f29\u53cb\u597d&#xff08;\u540c\u7c7b\u578b\u6570\u636e\u538b\u7f29\u7387\u9ad8&#xff0c;pl.read_parquet\u00a0\u662f\u4e3b\u6d41\u683c\u5f0f&#xff09;\u3002<\/li>\n<\/ul>\n<h4 id=\"25-\u6d41\u5f0f\u5904\u7406streaming\">2.5 \u6d41\u5f0f\u5904\u7406&#xff08;Streaming&#xff09;<\/h4>\n<p>\u9762\u5bf9\u300c\u8d85\u8fc7\u5185\u5b58\u300d\u7684\u6570\u636e&#xff0c;Polars \u63d0\u4f9b\u6d41\u5f0f\u6267\u884c&#xff1a;.collect(streaming&#061;True)&#xff0c;\u67e5\u8be2\u5f15\u64ce\u4f1a\u5728\u5fc5\u8981\u65f6\u628a\u4e2d\u95f4\u7ed3\u679c\u843d\u76d8&#xff08;\u5982\u6392\u5e8f\u3001\u805a\u5408&#xff09;&#xff0c;\u7528\u8fb9\u8bfb\u8fb9\u7b97\u4ee3\u66ff\u5168\u91cf\u8f7d\u5165\u5185\u5b58\u3002<\/p>\n<hr \/>\n<h3 id=\"3-\u5b89\u88c5\u4e0e\u5feb\u901f\u4e0a\u624b\">3. \u5b89\u88c5\u4e0e\u5feb\u901f\u4e0a\u624b<\/h3>\n<p>pip install polars          # \u5f53\u524d\u7a33\u5b9a\u7248 1.x<br \/>\npip install pyarrow         # \u53ef\u9009\u7684 Arrow \u4e92\u64cd\u4f5c\u6269\u5c55<br \/>\npip install polars[timezone]  # \u65f6\u533a\u652f\u6301<\/p>\n<p>Polars \u662f\u7f16\u8bd1\u597d\u7684\u4e8c\u8fdb\u5236 wheel&#xff0c;\u4e0d\u9700\u8981\u672c\u5730 Rust \u73af\u5883\u3002\u5bfc\u5165&#xff1a;<\/p>\n<p>import polars as pl<\/p>\n<p>\u4e94\u5206\u949f\u6700\u5c0f\u95ed\u73af&#xff1a;<\/p>\n<p># \u6784\u9020<br \/>\ndf &#061; pl.DataFrame({<br \/>\n    &#034;device&#034;: [&#034;CNC-01&#034;, &#034;CNC-01&#034;, &#034;CNC-02&#034;, &#034;CNC-02&#034;],<br \/>\n    &#034;ts&#034;: [&#034;2026-10-23 08:00:00&#034;, &#034;2026-10-23 08:00:01&#034;,<br \/>\n           &#034;2026-10-23 08:00:00&#034;, &#034;2026-10-23 08:00:01&#034;],<br \/>\n    &#034;value&#034;: [10.5, 12.1, 8.2, 9.0],<br \/>\n}).with_columns(pl.col(&#034;ts&#034;).str.to_datetime())<\/p>\n<p># \u8fc7\u6ee4 &#043; \u805a\u5408&#xff08;Polars \u98ce\u683c&#xff09;<br \/>\nresult &#061; (<br \/>\n    df.lazy()<br \/>\n    .filter(pl.col(&#034;value&#034;) &gt; 9)<br \/>\n    .group_by(&#034;device&#034;)<br \/>\n    .agg(pl.col(&#034;value&#034;).mean().alias(&#034;avg_value&#034;))<br \/>\n    .sort(&#034;avg_value&#034;, descending&#061;True)<br \/>\n    .collect()<br \/>\n)<br \/>\nprint(result)<\/p>\n<p>\u8f93\u51fa&#xff1a;<\/p>\n<p>shape: (2, 2)<br \/>\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n\u2502 device  \u2506 avg_value \u2502<br \/>\n\u255e\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u256a\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2561<br \/>\n\u2502 CNC-01  \u2506 11.3      \u2502<br \/>\n\u2502 CNC-02  \u2506 8.2       \u2502<br \/>\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518<\/p>\n<hr \/>\n<h3 id=\"4-api-\u8bf4\u660e\u9ad8\u9891\u901f\u67e5\">4. API \u8bf4\u660e&#xff08;\u9ad8\u9891\u901f\u67e5&#xff09;<\/h3>\n<h4 id=\"41-\u521b\u5efa\u4e0e-io\">4.1 \u521b\u5efa\u4e0e IO<\/h4>\n<table>\n<tbody>\n<tr>\u76ee\u7684API<\/tr>\n<tr>\n<td>\u4ece dict \/ list \/ numpy \u6784\u9020<\/td>\n<td>pl.DataFrame({&#8230;})\u3001pl.DataFrame(arr, schema&#061;&#8230;)<\/td>\n<\/tr>\n<tr>\n<td>\u8bfb CSV<\/td>\n<td>pl.read_csv(path, schema_overrides&#061;{&#8230;}, try_parse_dates&#061;True)<\/td>\n<\/tr>\n<tr>\n<td>\u8bfb Parquet \/ Arrow IPC<\/td>\n<td>pl.read_parquet(path)\u3001pl.read_ipc(path)<\/td>\n<\/tr>\n<tr>\n<td>\u8bfb JSON \/ NDJSON<\/td>\n<td>pl.read_json(path)\u3001pl.read_ndjson(path)<\/td>\n<\/tr>\n<tr>\n<td>\u8fde\u63a5\u6570\u636e\u5e93<\/td>\n<td>pl.read_database(uri&#061;&#8230;, query&#061;&#8230;)<\/td>\n<\/tr>\n<tr>\n<td>\u5199\u6587\u4ef6<\/td>\n<td>df.write_csv(&#8230;)\u3001df.write_parquet(&#8230;)\u3001df.write_json(&#8230;)\u3001df.write_ipc(&#8230;)<\/td>\n<\/tr>\n<tr>\n<td>\u4e0e Pandas \/ NumPy \u4e92\u8f6c<\/td>\n<td>df.to_pandas()\u3001df.to_numpy()\u3001pl.from_pandas(pd_df)\u3001pl.from_numpy(arr)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4 id=\"42-\u9009\u62e9\u4e0e\u64cd\u4f5c\u4e0a\u4e0b\u6587\">4.2 \u9009\u62e9\u4e0e\u64cd\u4f5c\u4e0a\u4e0b\u6587<\/h4>\n<table>\n<tbody>\n<tr>\u4e0a\u4e0b\u6587\u4f5c\u7528\u793a\u4f8b<\/tr>\n<tr>\n<td>df.select(&#8230;)<\/td>\n<td>\u9009\u5217 \/ \u8ba1\u7b97\u5217<\/td>\n<td>df.select(pl.col(&#034;a&#034;), (pl.col(&#034;b&#034;)*2).alias(&#034;b2&#034;))<\/td>\n<\/tr>\n<tr>\n<td>df.with_columns(&#8230;)<\/td>\n<td>\u65b0\u589e \/ \u8986\u76d6\u5217<\/td>\n<td>df.with_columns(pl.col(&#034;v&#034;).diff().alias(&#034;delta&#034;))<\/td>\n<\/tr>\n<tr>\n<td>df.filter(&#8230;)<\/td>\n<td>\u884c\u8fc7\u6ee4<\/td>\n<td>df.filter(pl.col(&#034;q&#034;) &#061;&#061; 1)<\/td>\n<\/tr>\n<tr>\n<td>df.group_by(&#8230;).agg(&#8230;)<\/td>\n<td>\u5206\u7ec4\u805a\u5408<\/td>\n<td>df.group_by(&#034;device&#034;).agg(pl.len(), pl.col(&#034;v&#034;).mean())<\/td>\n<\/tr>\n<tr>\n<td>df.sort(&#8230;)<\/td>\n<td>\u6392\u5e8f<\/td>\n<td>df.sort(&#034;ts&#034;)\u3001df.sort(pl.col(&#034;v&#034;).rank())<\/td>\n<\/tr>\n<tr>\n<td>df.unique()<\/td>\n<td>\u53bb\u91cd<\/td>\n<td>df.unique(subset&#061;[&#034;device&#034;])<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4 id=\"43-\u5217\u9009\u62e9\u8bed\u6cd5\">4.3 \u5217\u9009\u62e9\u8bed\u6cd5<\/h4>\n<ul>\n<li>pl.col(&#034;a&#034;)\u3001pl.col(&#034;a&#034;, &#034;b&#034;)\u3001pl.col(&#034;^prefix_.*$&#034;)&#xff08;\u6b63\u5219&#xff09;\u3001pl.all()\u3001pl.exclude(&#034;ts&#034;)&#xff1b;<\/li>\n<li>df.select(pl.col(&#034;a&#034;).name.prefix(&#034;raw_&#034;))\u00a0\u6279\u91cf\u6539\u540d&#xff1b;<\/li>\n<li>\u53d6\u5b50\u96c6&#xff1a;df.select([&#034;device&#034;, &#034;value&#034;])\u00a0\u76f4\u63a5\u4f20\u5b57\u7b26\u4e32\u5217\u8868\u4e5f\u53ef\u4ee5\u3002<\/li>\n<\/ul>\n<h4 id=\"44-\u5e38\u7528\u8868\u8fbe\u5f0f\u51fd\u6570\u65cf\">4.4 \u5e38\u7528\u8868\u8fbe\u5f0f\u51fd\u6570\u65cf<\/h4>\n<table>\n<tbody>\n<tr>\u7c7b\u522b\u8868\u8fbe\u5f0f<\/tr>\n<tr>\n<td>\u6570\u503c<\/td>\n<td>sum\/mean\/median\/std\/var\/min\/max\u3001diff\u3001pct_change\u3001rank\u3001cum_sum\u3001clip\u3001round\u3001abs\u3001log\u3001pow\u3001shift<\/td>\n<\/tr>\n<tr>\n<td>\u5b57\u7b26\u4e32<\/td>\n<td>str.len_chars\u3001str.contains\u3001str.starts_with\u3001str.to_uppercase\u3001str.split\u3001str.extract\u3001str.replace<\/td>\n<\/tr>\n<tr>\n<td>\u65f6\u95f4<\/td>\n<td>dt.year\/month\/day\/hour\/minute\/second\u3001dt.truncate(&#034;1h&#034;)\u3001dt.round(&#034;5m&#034;)\u3001dt.epoch(&#034;s&#034;)\u3001dt.strftime<\/td>\n<\/tr>\n<tr>\n<td>\u6761\u4ef6<\/td>\n<td>pl.when(cond).then(a).otherwise(b)&#xff08;\u5bf9\u6807\u00a0np.where&#xff09;\u3001is_in\u3001is_null\u3001is_between<\/td>\n<\/tr>\n<tr>\n<td>\u805a\u5408<\/td>\n<td>first\/last\/n_unique\/unique\/count\/len\u3001quantile(0.95)\u3001arg_max\/arg_min\u3001n_unique<\/td>\n<\/tr>\n<tr>\n<td>\u5217\u8868\/\u7ed3\u6784<\/td>\n<td>list.len\u3001list.first\u3001list.sum\u3001list.eval\u3001struct.field<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4 id=\"45-\u7a97\u53e3\u51fd\u6570\">4.5 \u7a97\u53e3\u51fd\u6570<\/h4>\n<p>over()\u00a0\u662f Polars \u7684\u5206\u7ec4\u7a97\u53e3\u8bed\u6cd5&#xff0c;\u5bf9\u6807 SQL \u7684\u00a0PARTITION BY&#xff1a;<\/p>\n<p>df.with_columns(<br \/>\n    pl.col(&#034;value&#034;).mean().over(&#034;device&#034;).alias(&#034;device_avg&#034;),      # \u7ec4\u5185\u5747\u503c\u5e7f\u64ad<br \/>\n    pl.col(&#034;value&#034;).rank().over([&#034;device&#034;, pl.col(&#034;ts&#034;).dt.hour()]).alias(&#034;rank_in_hour&#034;),<br \/>\n)<\/p>\n<h4 id=\"46-join\">4.6 Join<\/h4>\n<p>df1.join(df2, on&#061;&#034;device&#034;, how&#061;&#034;left&#034;)        # left\/right\/inner\/outer\/anti\/semi\/cross<br \/>\ndf1.join_asof(df2, on&#061;&#034;ts&#034;, by&#061;&#034;device&#034;)      # \u6700\u8fd1\u65f6\u95f4\u5339\u914d&#xff0c;\u5de5\u4e1a\u65f6\u5e8f\u5bf9\u9f50\u795e\u5668<\/p>\n<p>join_asof\u00a0\u662f Polars&#xff08;\u53ca DuckDB&#xff09;\u72ec\u6709\u4eae\u70b9&#xff1a;\u4e24\u8868\u6309\u65f6\u95f4\u5c31\u8fd1\u5bf9\u9f50&#xff0c;\u505a\u8bbe\u5907\u6863\u6848\u4e0e\u70b9\u4f4d\u660e\u7ec6\u5173\u8054\u65f6\u4e0d\u9700\u8981\u5148\u505a\u65f6\u95f4\u5206\u7bb1\u3002<\/p>\n<h4 id=\"47-\u5176\u4ed6\u9ad8\u9891\u65b9\u6cd5\">4.7 \u5176\u4ed6\u9ad8\u9891\u65b9\u6cd5<\/h4>\n<ul>\n<li>df.describe()&#xff1a;\u7edf\u8ba1\u6458\u8981&#xff1b;<\/li>\n<li>df.head()\/tail()\u3001df.sample(n&#061;1000)&#xff1a;\u62bd\u6837&#xff1b;<\/li>\n<li>df.explode(&#034;list_col&#034;)&#xff1a;\u628a\u5217\u8868\u5217\u70b8\u5f00\u6210\u591a\u884c&#xff1b;<\/li>\n<li>df.pivot(values&#061;&#034;v&#034;, index&#061;&#034;device&#034;, columns&#061;&#034;hour&#034;)&#xff1a;\u900f\u89c6&#xff1b;<\/li>\n<li>df.estimated_size()&#xff1a;\u4f30\u7b97\u5185\u5b58&#xff1b;<\/li>\n<li>df.glimpse()&#xff1a;\u5217\u7c7b\u578b\u5feb\u901f\u9884\u89c8&#xff08;\u7c7b\u4f3c\u00a0df.info()&#xff09;\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3 id=\"5-\u8be6\u7ec6\u4f7f\u7528\u8bf4\u660e8-\u7ec4\u53ef\u8fd0\u884c\u793a\u4f8b\">5. \u8be6\u7ec6\u4f7f\u7528\u8bf4\u660e&#xff08;8 \u7ec4\u53ef\u8fd0\u884c\u793a\u4f8b&#xff09;<\/h3>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u56f4\u7ed5\u5de5\u4e1a\u6570\u91c7\u573a\u666f\u7ec4\u7ec7&#xff0c;\u5168\u90e8\u53ef\u76f4\u63a5\u8fd0\u884c\u3002<\/p>\n<h4 id=\"51-\u6700\u5c0f\u95ed\u73af\u4ece-csv-\u8bfb\u70b9\u4f4d\u660e\u7ec6\u5e76\u505a\u5206\u949f\u7ea7\u805a\u5408\">5.1 \u6700\u5c0f\u95ed\u73af&#xff1a;\u4ece CSV \u8bfb\u70b9\u4f4d\u660e\u7ec6\u5e76\u505a\u5206\u949f\u7ea7\u805a\u5408<\/h4>\n<p>import polars as pl<\/p>\n<p># \u6a21\u62df 1 \u53f0\u8bbe\u5907 3 \u5929\u7684\u79d2\u7ea7\u70b9\u4f4d&#xff08;\u8fd9\u91cc\u76f4\u63a5\u9020\u6570\u636e&#xff0c;\u5b9e\u9645\u7528 pl.read_csv&#xff09;<br \/>\ndf &#061; pl.DataFrame({<br \/>\n    &#034;device&#034;: [&#034;CNC-01&#034;] * 259200,<br \/>\n    &#034;ts&#034;: pl.datetime_range(<br \/>\n        start&#061;&#034;2026-10-20 00:00:00&#034;, end&#061;&#034;2026-10-22 23:59:59&#034;,<br \/>\n        interval&#061;&#034;1s&#034;, eager&#061;True,<br \/>\n    ),<br \/>\n    &#034;load&#034;: [60 &#043; (i % 40) for i in range(259200)],<br \/>\n}).with_columns(pl.col(&#034;ts&#034;).dt.cast_time_unit(&#034;ms&#034;).alias(&#034;ts_ms&#034;))<\/p>\n<p>minute_stats &#061; (<br \/>\n    df.lazy()<br \/>\n    .with_columns(pl.col(&#034;ts&#034;).dt.truncate(&#034;1m&#034;).alias(&#034;minute&#034;))<br \/>\n    .group_by([&#034;device&#034;, &#034;minute&#034;])<br \/>\n    .agg(<br \/>\n        pl.col(&#034;load&#034;).mean().alias(&#034;avg_load&#034;),<br \/>\n        pl.col(&#034;load&#034;).max().alias(&#034;max_load&#034;),<br \/>\n        pl.col(&#034;load&#034;).quantile(0.95).alias(&#034;p95_load&#034;),<br \/>\n    )<br \/>\n    .collect()<br \/>\n)<br \/>\nprint(minute_stats.head())<\/p>\n<p>\u8981\u70b9&#xff1a;dt.truncate(&#034;1m&#034;)\u00a0\u628a\u65f6\u95f4\u5bf9\u9f50\u5230\u5206\u949f&#xff1b;group_by\u00a0\u5185\u4e00\u6b21\u6027\u7b97\u4e09\u4e2a\u6307\u6807&#xff0c;\u6bd4 Pandas \u4e09\u6b21 agg \u518d concat \u7701\u5f97\u591a\u3002<\/p>\n<h4 id=\"52-\u60f0\u6027\u67e5\u8be2\u4f18\u5316\u4e09\u6b65\u6d41\u6c34\u7ebf\u5408\u5e76\u4e3a\u4e00\u6b21\u6267\u884c\">5.2 \u60f0\u6027\u67e5\u8be2\u4f18\u5316&#xff1a;\u4e09\u6b65\u6d41\u6c34\u7ebf\u5408\u5e76\u4e3a\u4e00\u6b21\u6267\u884c<\/h4>\n<p># \u5148 lzma&#xff0c;\u518d collect&#xff1a;\u4e2d\u95f4\u4e0d\u4ea7\u751f\u4e34\u65f6 DataFrame<br \/>\nplan &#061; (<br \/>\n    df.lazy()<br \/>\n    .filter(pl.col(&#034;load&#034;) &gt; 50)<br \/>\n    .with_columns((pl.col(&#034;load&#034;) &#8211; 60).alias(&#034;overload&#034;))<br \/>\n    .group_by(&#034;device&#034;)<br \/>\n    .agg(pl.col(&#034;overload&#034;).mean())<br \/>\n)<br \/>\nprint(plan.explain())        # \u67e5\u770b\u4f18\u5316\u540e\u7684\u6267\u884c\u8ba1\u5212<br \/>\nresult &#061; plan.collect()      # \u771f\u6b63\u6267\u884c<\/p>\n<p>explain()\u00a0\u80fd\u76f4\u63a5\u770b\u5230&#xff1a;Polars \u4f1a\u628a\u00a0filter\u00a0\u4e0b\u63a8\u5230\u8bfb\u53d6\u9636\u6bb5&#xff08;ProjectionPushdown&#xff09;&#xff0c;\u6574\u6761\u94fe\u8def\u53ea\u626b\u63cf\u4e00\u6b21\u6570\u636e\u3002<\/p>\n<h4 id=\"53-\u7a97\u53e3\u51fd\u6570\u8bbe\u5907\u65e5\u5747\u503c-\u76f8\u5bf9\u504f\u5dee\">5.3 \u7a97\u53e3\u51fd\u6570&#xff1a;\u8bbe\u5907\u65e5\u5747\u503c &#043; \u76f8\u5bf9\u504f\u5dee<\/h4>\n<p>df.with_columns(<br \/>\n    pl.col(&#034;ts&#034;).dt.date().alias(&#034;day&#034;),<br \/>\n).with_columns(<br \/>\n    (pl.col(&#034;load&#034;) \/ pl.col(&#034;load&#034;).mean().over([&#034;device&#034;, &#034;day&#034;]) &#8211; 1).alias(&#034;deviation&#034;),<br \/>\n).select(&#034;device&#034;, &#034;day&#034;, &#034;deviation&#034;).head()<\/p>\n<h4 id=\"54-\u591a\u8868\u5173\u8054\u70b9\u4f4d\u660e\u7ec6-\u8bbe\u5907\u6863\u6848-\u5de5\u827a\u53c2\u6570\">5.4 \u591a\u8868\u5173\u8054&#xff1a;\u70b9\u4f4d\u660e\u7ec6 \u00d7 \u8bbe\u5907\u6863\u6848 \u00d7 \u5de5\u827a\u53c2\u6570<\/h4>\n<p>details &#061; pl.DataFrame({&#8230;})          # \u79d2\u7ea7\u70b9\u4f4d<br \/>\ndevices &#061; pl.DataFrame({               # \u8bbe\u5907\u6863\u6848<br \/>\n    &#034;device&#034;: [&#034;CNC-01&#034;, &#034;CNC-02&#034;],<br \/>\n    &#034;line&#034;: [&#034;L1&#034;, &#034;L2&#034;],<br \/>\n    &#034;model&#034;: [&#034;VMC-850&#034;, &#034;VMC-1060&#034;],<br \/>\n})<br \/>\nlimits &#061; pl.DataFrame({                # \u5de5\u827a\u53c2\u6570\u9608\u503c<br \/>\n    &#034;model&#034;: [&#034;VMC-850&#034;, &#034;VMC-1060&#034;],<br \/>\n    &#034;load_hi&#034;: [85, 88],<br \/>\n})<\/p>\n<p>enriched &#061; (<br \/>\n    details<br \/>\n    .join(devices, on&#061;&#034;device&#034;, how&#061;&#034;left&#034;)<br \/>\n    .join(limits, on&#061;&#034;model&#034;, how&#061;&#034;left&#034;)<br \/>\n    .with_columns(<br \/>\n        pl.when(pl.col(&#034;load&#034;) &gt; pl.col(&#034;load_hi&#034;))<br \/>\n        .then(pl.lit(&#034;ALARM&#034;)).otherwise(pl.lit(&#034;OK&#034;)).alias(&#034;status&#034;)<br \/>\n    )<br \/>\n)<\/p>\n<h4 id=\"55-join_asof\u6863\u6848\u53d8\u66f4\u4e0e\u70b9\u4f4d\u65f6\u5e8f\u5bf9\u9f50\">5.5 join_asof&#xff1a;\u6863\u6848\u53d8\u66f4\u4e0e\u70b9\u4f4d\u65f6\u5e8f\u5bf9\u9f50<\/h4>\n<p>events &#061; pl.DataFrame({  # \u6362\u5200\u3001\u6539\u53c2\u7b49\u4e8b\u4ef6<br \/>\n    &#034;ts&#034;: [&#034;2026-10-22 09:10:00&#034;, &#034;2026-10-22 14:30:00&#034;],<br \/>\n    &#034;device&#034;: [&#034;CNC-01&#034;, &#034;CNC-01&#034;],<br \/>\n    &#034;event&#034;: [&#034;tool_change&#034;, &#034;param_update&#034;],<br \/>\n}).with_columns(pl.col(&#034;ts&#034;).str.to_datetime())<\/p>\n<p>aligned &#061; df.join_asof(events, on&#061;&#034;ts&#034;, by&#061;&#034;device&#034;, strategy&#061;&#034;backward&#034;)<\/p>\n<p>\u6bcf\u4e2a\u70b9\u4f4d\u81ea\u52a8\u5e26\u4e0a\u6700\u8fd1\u4e00\u6b21\u53d1\u751f\u7684\u4e8b\u4ef6&#xff0c;\u505a\u6839\u56e0\u56de\u6eaf\u975e\u5e38\u597d\u7528\u3002<\/p>\n<h4 id=\"56-\u6d41\u5f0f\u5904\u7406\u5904\u7406\u8d85\u8fc7\u5185\u5b58\u7684-parquet\">5.6 \u6d41\u5f0f\u5904\u7406&#xff1a;\u5904\u7406\u8d85\u8fc7\u5185\u5b58\u7684 Parquet<\/h4>\n<p># \u5047\u8bbe hourly \u76ee\u5f55\u4e0b\u6709 10 GB Parquet \u5206\u7247<br \/>\nlf &#061; pl.scan_parquet(&#034;data\/hourly\/*.parquet&#034;)   # scan_* \u7cfb\u5217\u5929\u7136\u60f0\u6027<br \/>\nsummary &#061; (<br \/>\n    lf.filter(pl.col(&#034;q&#034;) &#061;&#061; 1)<br \/>\n    .group_by([&#034;device&#034;, pl.col(&#034;ts&#034;).dt.truncate(&#034;1h&#034;)])<br \/>\n    .agg(pl.col(&#034;value&#034;).mean())<br \/>\n    .collect(streaming&#061;True)<br \/>\n)<\/p>\n<p>scan_parquet\u00a0\u53ea\u8bfb\u53d6\u67e5\u8be2\u6240\u9700\u7684\u5217&#xff08;\u5217\u88c1\u526a&#xff09;&#043; \u53ea\u8bfb\u53d6\u6ee1\u8db3\u8fc7\u6ee4\u7684\u884c\u7ec4&#xff08;\u8c13\u8bcd\u4e0b\u63a8&#xff09;&#xff0c;\u914d\u5408\u00a0streaming&#061;True\u00a0\u53ef\u4ee5\u5904\u7406\u8fdc\u8d85\u5185\u5b58\u7684\u6570\u636e\u3002<\/p>\n<h4 id=\"57-\u4e0e-pandas-matplotlib-\u4e92\u64cd\u4f5c\">5.7 \u4e0e Pandas \/ Matplotlib \u4e92\u64cd\u4f5c<\/h4>\n<p># Polars \u7b97&#xff0c;Pandas\/Matplotlib \u753b&#xff08;\u6216\u76f4\u63a5 Matplotlib \u6d88\u8d39 numpy&#xff09;<br \/>\nimport matplotlib.pyplot as plt<\/p>\n<p>trend &#061; (<br \/>\n    df.lazy()<br \/>\n    .group_by(pl.col(&#034;ts&#034;).dt.truncate(&#034;1h&#034;))<br \/>\n    .agg(pl.col(&#034;load&#034;).mean())<br \/>\n    .collect()<br \/>\n)<br \/>\nplt.plot(trend[&#034;ts&#034;].to_numpy(), trend[&#034;load&#034;].to_numpy())<\/p>\n<h4 id=\"58-\u751f\u4ea7\u9aa8\u67b6\u6279\u91cf\u843d\u76d8-\u589e\u91cf\u8ffd\u52a0-\u538b\u7f29\">5.8 \u751f\u4ea7\u9aa8\u67b6&#xff1a;\u6279\u91cf\u843d\u76d8 &#043; \u589e\u91cf\u8ffd\u52a0 &#043; \u538b\u7f29<\/h4>\n<p># \u6bcf\u5c0f\u65f6\u628a\u805a\u5408\u7ed3\u679c\u8ffd\u52a0\u5230 Parquet&#xff08;\u7528 pyarrow \u6216\u76f4\u63a5\u5199\u5206\u7247\u6587\u4ef6&#xff09;<br \/>\ndef write_hourly(df: pl.DataFrame, base: str):<br \/>\n    hour &#061; df[&#034;ts&#034;].min().strftime(&#034;%Y%m%d_%H&#034;)<br \/>\n    path &#061; f&#034;{base}\/agg_{hour}.parquet&#034;<br \/>\n    df.write_parquet(path, compression&#061;&#034;zstd&#034;, compression_level&#061;19)<\/p>\n<hr \/>\n<h3 id=\"6-\u5e95\u5c42\u5b9e\u73b0\u5256\u6790\u5b83\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u5feb\">6. \u5e95\u5c42\u5b9e\u73b0\u5256\u6790&#xff08;\u5b83\u4e3a\u4ec0\u4e48\u8fd9\u4e48\u5feb&#xff09;<\/h3>\n<h4 id=\"61-apache-arrow-\u5217\u5f0f\u5185\u5b58\u683c\u5f0f\">6.1 Apache Arrow \u5217\u5f0f\u5185\u5b58\u683c\u5f0f<\/h4>\n<p>Polars \u7684\u6240\u6709\u6570\u636e\u90fd\u88c5\u5728\u00a0Arrow \u7684 ChunkedArray\u00a0\u91cc\u3002\u6bcf\u5217\u662f\u4e00\u5757\u8fde\u7eed\u7684\u540c\u7c7b\u578b\u7f13\u51b2&#xff0c;\u53e6\u5916\u8fd8\u6709\u4e00\u4e2a validity bitmap&#xff08;\u4f4d\u56fe&#xff09;\u8868\u793a\u7a7a\u503c\u2014\u2014\u6240\u4ee5\u7a7a\u503c\u4e0d\u9700\u8981\u5355\u72ec\u7684 NaN \u54e8\u5175&#xff0c;\u4e5f\u4e0d\u5360 8 \u5b57\u8282\u3002\u5185\u5b58\u5e03\u5c40\u5bf9 CPU \u7f13\u5b58\u6781\u5ea6\u53cb\u597d&#xff1a;\u626b\u63cf\u4e00\u5217 &#061; \u987a\u5e8f\u8bfb\u4e00\u7247\u8fde\u7eed\u5185\u5b58\u3002<\/p>\n<h4 id=\"62-\u591a\u7ebf\u7a0b\u5e76\u884c\">6.2 \u591a\u7ebf\u7a0b\u5e76\u884c<\/h4>\n<p>Polars \u9ed8\u8ba4\u4f7f\u7528\u673a\u5668\u5168\u90e8\u6838\u5fc3\u3002\u5b83\u7684\u5e76\u884c\u7b56\u7565\u662f&#xff1a;<\/p>\n<ul>\n<li>\u6309\u5217\u5e76\u884c&#xff1a;select\u00a0\u91cc\u591a\u4e2a\u8868\u8fbe\u5f0f\u53ef\u4ee5\u5e76\u884c\u6c42\u503c&#xff1b;<\/li>\n<li>\u6309\u5757\u5e76\u884c&#xff1a;\u5355\u5217\u64cd\u4f5c\u628a\u6570\u636e\u5207\u6210 chunk \u5e76\u884c\u5904\u7406&#xff0c;\u518d\u62fc\u63a5&#xff1b;<\/li>\n<li>\u6309\u7ec4\u5e76\u884c&#xff1a;group_by\u00a0\u5148\u5e76\u884c\u54c8\u5e0c\u5206\u7ec4&#xff0c;\u518d\u5408\u5e76\u5404\u7ec4\u7ed3\u679c\u3002<\/li>\n<\/ul>\n<p>\u5bf9\u6bd4 Pandas \u7684\u5355\u7ebf\u7a0b&#xff0c;8 \u6838\u673a\u5668\u4e0a\u7eaf\u8ba1\u7b97\u4efb\u52a1\u8f7b\u677e\u5feb 5~20 \u500d\u3002<\/p>\n<h4 id=\"63-simd-\u5411\u91cf\u5316\">6.3 SIMD \u5411\u91cf\u5316<\/h4>\n<p>Rust \u7f16\u8bd1\u5668&#xff08;LLVM&#xff09;\u81ea\u52a8\u4e3a\u70ed\u5faa\u73af\u751f\u6210 AVX2\/AVX-512 \u6307\u4ee4&#xff0c;\u4e00\u6b21\u5904\u7406 8 \u4e2a float64 \u6216 16 \u4e2a int32\u3002\u5217\u5f0f\u5e03\u5c40\u8ba9\u300c\u6574\u5217\u662f\u8fde\u7eed\u540c\u7c7b\u578b\u6570\u7ec4\u300d\u6210\u4e3a\u5e38\u6001&#xff0c;SIMD \u6536\u76ca\u6700\u5927\u5316\u3002<\/p>\n<h4 id=\"64-\u67e5\u8be2\u4f18\u5316\u5668lazy-\u7684\u79d8\u5bc6\">6.4 \u67e5\u8be2\u4f18\u5316\u5668&#xff08;Lazy \u7684\u79d8\u5bc6&#xff09;<\/h4>\n<p>Polars \u7684 LazyFrame \u4f1a\u505a\u4ee5\u4e0b\u4f18\u5316&#xff08;explain()\u00a0\u53ef\u89c1&#xff09;&#xff1a;<\/p>\n<ul>\n<li>Predicate Pushdown&#xff1a;\u628a\u00a0filter\u00a0\u5c3d\u91cf\u63a8\u5230\u8bfb\u53d6\/\u626b\u63cf\u9636\u6bb5&#xff0c;\u53ea\u8bfb\u9700\u8981\u7684\u884c&#xff1b;<\/li>\n<li>Projection Pushdown&#xff1a;\u53ea\u8bfb\u53d6\/\u8ba1\u7b97\u9700\u8981\u7684\u5217&#xff1b;<\/li>\n<li>Slice Pushdown&#xff1a;head\/tail\u00a0\u63d0\u524d\u622a\u65ad&#xff1b;<\/li>\n<li>CSE&#xff08;\u516c\u5171\u5b50\u8868\u8fbe\u5f0f\u6d88\u9664&#xff09;&#xff1a;\u591a\u4e2a\u8868\u8fbe\u5f0f\u91cd\u590d\u8ba1\u7b97\u7684\u90e8\u5206\u53ea\u7b97\u4e00\u6b21&#xff1b;<\/li>\n<li>Join \u91cd\u6392&#xff1a;\u5c0f\u8868\u4f18\u5148\u3001hash join \u7b49\u7b56\u7565\u9009\u62e9\u3002<\/li>\n<\/ul>\n<h4 id=\"65-\u8868\u8fbe\u5f0f\u7cfb\u7edf\u4e0e\u96f6\u4e2d\u95f4\u5e27\">6.5 \u8868\u8fbe\u5f0f\u7cfb\u7edf\u4e0e\u96f6\u4e2d\u95f4\u5e27<\/h4>\n<p>\u8868\u8fbe\u5f0f\u662f\u00a0AST&#xff08;\u62bd\u8c61\u8bed\u6cd5\u6811&#xff09;&#xff1a;pl.col(&#034;load&#034;).mean().over(&#034;device&#034;)\u00a0\u6784\u5efa\u4e00\u68f5\u6811&#xff0c;\u6267\u884c\u65f6\u7531\u5f15\u64ce\u7edf\u4e00\u8c03\u5ea6\u3002\u6b63\u56e0\u4e3a Lazy \u6a21\u5f0f\u6574\u68f5\u6811\u4e00\u6b21\u6267\u884c&#xff0c;\u4e2d\u95f4\u4e0d\u4f1a\u7269\u5316\u4e34\u65f6 DataFrame&#xff0c;\u5185\u5b58\u5cf0\u503c\u5927\u5e45\u4e0b\u964d\u2014\u2014\u8fd9\u662f Pandas \u6025\u5207\u6267\u884c\u65e0\u6cd5\u907f\u514d\u7684\u75db\u70b9\u3002<\/p>\n<h4 id=\"66-\u5185\u5b58\u4e0e\u7f13\u5b58\u7b56\u7565\">6.6 \u5185\u5b58\u4e0e\u7f13\u5b58\u7b56\u7565<\/h4>\n<ul>\n<li>\u5927\u6587\u4ef6\u8bfb\u53d6\u4f7f\u7528 mmap&#xff08;scan_parquet\u00a0\u4f9d\u8d56 Arrow \u7684\u5185\u5b58\u6620\u5c04&#xff09;&#xff1b;<\/li>\n<li>\u5199\u5165\u4f7f\u7528\u6279\u7f13\u51b2&#xff1b;collect(streaming&#061;True)\u00a0\u65f6\u6392\u5e8f\u3001\u805a\u5408\u7b49\u7b97\u5b50\u81ea\u52a8 spill \u5230\u78c1\u76d8\u4e34\u65f6\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3 id=\"7-\u5e38\u9519\u70b9-\u575120-\u6761\u5b9e\u6218\u6392\u96f7\">7. \u5e38\u9519\u70b9 \/ \u5751&#xff08;20&#043; \u6761\u5b9e\u6218\u6392\u96f7&#xff09;<\/h3>\n<li>\u5fd8\u00a0collect()&#xff1a;LazyFrame \u4e0a\u00a0print()\u00a0\u663e\u793a\u7684\u662f\u67e5\u8be2\u8ba1\u5212\u800c\u4e0d\u662f\u6570\u636e&#xff1b;\u4efb\u4f55\u00a0lazy()\u00a0\u94fe\u6700\u540e\u5fc5\u987b\u00a0.collect()\u3002<\/li>\n<li>collect()\u00a0\u540e\u7ee7\u7eed\u5f53 Lazy \u7528&#xff1a;collect\u00a0\u8fd4\u56de\u7684\u662f\u666e\u901a DataFrame&#xff0c;\u518d\u8c03\u00a0lazy()\u00a0\u624d\u80fd\u7ee7\u7eed\u60f0\u6027\u3002<\/li>\n<li>\u5217\u540d\u5927\u5c0f\u5199\u654f\u611f&#xff1a;Polars \u5217\u540d\u4e25\u683c\u533a\u5206\u5927\u5c0f\u5199&#xff0c;col(&#034;Device&#034;)\u00a0\u627e\u4e0d\u5230\u00a0device\u00a0\u4f1a\u76f4\u63a5\u62a5\u9519&#xff08;Pandas \u4e5f\u662f&#xff0c;\u4f46\u9519\u8bef\u4fe1\u606f\u66f4\u53cb\u597d&#xff09;\u3002<\/li>\n<li>\u9690\u5f0f\u7c7b\u578b\u8f6c\u6362\u4e0d\u5b58\u5728&#xff1a;pl.col(&#034;a&#034;) &#043; pl.col(&#034;b&#034;)\u00a0\u4e24\u8fb9\u7c7b\u578b\u4e0d\u4e00\u81f4&#xff08;\u5982 Int64 &#043; String&#xff09;\u76f4\u63a5\u629b\u00a0ComputeError&#xff0c;\u8fd9\u662f\u7279\u6027\u4e0d\u662f bug&#xff0c;\u903c\u4f60\u663e\u5f0f\u00a0.cast()\u3002<\/li>\n<li>\u7a7a\u503c\u4f20\u64ad&#xff1a;mean()\u00a0\u9ed8\u8ba4\u8df3\u8fc7 null&#xff08;\u4e0e SQL \u4e00\u81f4&#xff09;&#xff0c;\u4f46\u00a0sum()\u00a0\u4e5f\u662f\u8df3\u8fc7&#xff1b;\u9700\u8981\u00a0null\u00a0\u53c2\u4e0e\u65f6\u7528\u00a0pl.col(&#034;v&#034;).sum().fill_null(0)\u00a0\u4e4b\u7c7b\u663e\u5f0f\u5904\u7406\u3002<\/li>\n<li>when().then().otherwise()\u00a0\u7f3a\u00a0otherwise\u00a0\u8fd4\u56de null&#xff1a;\u5fd8\u8bb0\u5199\u00a0otherwise&#xff0c;\u6761\u4ef6\u4e0d\u6ee1\u8db3\u7684\u884c\u4f1a\u53d8 null&#xff0c;\u800c\u4e0d\u662f\u4fdd\u7559\u539f\u503c\u3002<\/li>\n<li>\u7528 Pandas \u601d\u7ef4\u5199 Polars&#xff1a;df[df[&#034;a&#034;]&gt;1]\u00a0\u5728 Polars \u91cc\u542b\u4e49\u5b8c\u5168\u4e0d\u540c&#xff08;\u90a3\u662f\u5217\u9009\u62e9&#xff01;&#xff09;&#xff0c;\u5fc5\u987b\u5199\u00a0df.filter(pl.col(&#034;a&#034;) &gt; 1)\u3002<\/li>\n<li>group_by\u00a0\u540e\u5fd8\u8bb0\u00a0agg&#xff1a;df.group_by(&#034;device&#034;)\u00a0\u5355\u72ec\u8c03\u7528\u6ca1\u6709\u610f\u4e49&#xff0c;\u5fc5\u987b\u8ddf\u00a0.agg(&#8230;)\u00a0\u6216\u00a0.len()\u3002<\/li>\n<li>\u805a\u5408\u4e2d\u6df7\u7528\u00a0alias\u00a0\u4e0e\u5217\u540d&#xff1a;\u805a\u5408\u5b57\u6bb5\u540d\u9ed8\u8ba4\u662f\u8868\u8fbe\u5f0f\u672c\u8eab&#xff0c;\u5efa\u8bae\u603b\u662f\u663e\u5f0f\u00a0.alias()&#xff0c;\u5426\u5219\u540e\u7eed\u00a0select\u00a0\u5f15\u7528\u5f88\u522b\u626d\u3002<\/li>\n<li>\u65f6\u95f4\u5b57\u7b26\u4e32\u6ca1\u6709\u8f6c Datetime \u5c31\u505a\u00a0dt.*&#xff1a;pl.col(&#034;ts&#034;).dt.hour()\u00a0\u524d\u5fc5\u987b\u5148\u00a0str.to_datetime()&#xff0c;\u5426\u5219\u62a5\u9519\u6216\u5f97\u5230 null\u3002<\/li>\n<li>\u65f6\u533a\u9677\u9631&#xff1a;\u5e26\u00a0&#043;08:00\u00a0\u7684\u5b57\u7b26\u4e32\u76f4\u63a5\u00a0str.to_datetime()\u00a0\u53ef\u80fd\u89e3\u6790\u4e3a\u65e0\u65f6\u533a&#xff1b;\u5efa\u8bae\u7edf\u4e00\u00a0str.to_datetime(time_zone&#061;&#034;Asia\/Shanghai&#034;)\u00a0\u6216\u5148\u00a0dt.convert_time_zone\u3002<\/li>\n<li>read_csv\u00a0\u65e5\u671f\u4e0d\u81ea\u52a8\u89e3\u6790&#xff1a;Polars \u4e0d\u4f1a\u50cf Pandas \u90a3\u6837\u81ea\u52a8\u731c\u65e5\u671f\u5217&#xff0c;\u9700\u8981\u00a0try_parse_dates&#061;True\u00a0\u6216\u00a0schema_overrides\u00a0\u624b\u52a8\u6307\u5b9a\u3002<\/li>\n<li>\u5927\u6587\u4ef6\u76f4\u63a5\u00a0read_csv\u00a0\u7206\u5185\u5b58&#xff1a;\u80fd\u00a0scan_csv\u00a0\u5c31\u4e0d\u8981\u00a0read_csv&#xff1b;\u8d85\u8fc7\u5185\u5b58\u7528\u6d41\u5f0f\u3002<\/li>\n<li>write_parquet\u00a0\u5fd8\u8bb0\u538b\u7f29\u53c2\u6570&#xff1a;\u9ed8\u8ba4 snappy \u591f\u7528&#xff0c;\u4f46\u51b7\u6570\u636e\u5efa\u8bae\u00a0compression&#061;&#034;zstd&#034;&#xff0c;\u6587\u4ef6\u80fd\u5c0f\u4e00\u534a\u4ee5\u4e0a\u3002<\/li>\n<li>join\u00a0\u9ed8\u8ba4 how \u662f inner&#xff1a;\u9700\u8981\u4fdd\u7559\u5de6\u8868\u5168\u90e8\u884c\u65f6\u8bb0\u5f97\u5199\u00a0how&#061;&#034;left&#034;\u3002<\/li>\n<li>join\u00a0\u952e\u7c7b\u578b\u4e0d\u4e00\u81f4&#xff1a;device\u00a0\u4e00\u8fb9\u662f String \u4e00\u8fb9\u662f Categorical \u4f1a\u62a5\u9519\u6216\u7ed3\u679c\u4e3a\u7a7a&#xff0c;\u5148\u00a0cast(pl.String)\u00a0\u7edf\u4e00\u3002<\/li>\n<li>join_asof\u00a0\u7684\u4e24\u8868\u90fd\u5fc5\u987b\u6309 key \u6392\u5e8f&#xff1a;\u4e0d\u6392\u5e8f\u7ed3\u679c\u4e71\u5957&#xff0c;\u5148\u00a0.sort(&#034;ts&#034;)\u3002<\/li>\n<li>over()\u00a0\u5206\u7ec4\u5b57\u6bb5\u662f\u8868\u8fbe\u5f0f\u800c\u975e\u5b57\u7b26\u4e32\u65f6\u5fd8\u5217\u8868\u5305\u88f9&#xff1a;pl.col(&#034;v&#034;).mean().over([&#034;device&#034;, pl.col(&#034;ts&#034;).dt.hour()])\u00a0\u8981\u4f20\u5217\u8868\u3002<\/li>\n<li>shift\u00a0\u8fb9\u754c\u884c\u4e3a&#xff1a;df.with_columns(pl.col(&#034;v&#034;).shift(1))\u00a0\u9996\u884c\u662f null&#xff0c;\u4e0d\u662f 0\u3002<\/li>\n<li>unique(subset&#061;&#8230;)\u00a0\u4e0e\u00a0n_unique\u00a0\u6df7\u6dc6&#xff1a;df.unique(subset&#061;[&#034;device&#034;])\u00a0\u8fd4\u56de\u53bb\u91cd\u540e\u7684\u5e27&#xff1b;pl.col(&#034;device&#034;).n_unique()\u00a0\u662f\u8ba1\u6570\u3002<\/li>\n<li>pivot\u00a0\u53c2\u6570\u987a\u5e8f&#xff1a;df.pivot(values&#061;&#8230;, index&#061;&#8230;, columns&#061;&#8230;, aggregate_function&#061;&#034;mean&#034;)&#xff0c;\u987a\u5e8f\u5199\u53cd\u4f1a\u62a5\u9519\u3002<\/li>\n<li>List\/Struct \u5217\u5c0f\u5fc3&#xff1a;\u5bf9 List \u5217\u505a\u7b97\u672f\u8981\u5148\u00a0list.eval\u00a0\u6216\u00a0explode&#xff0c;\u76f4\u63a5\u00a0col(&#034;list_col&#034;) &#043; 1\u00a0\u4e0d\u53ef\u7528\u3002<\/li>\n<li>filter\u00a0\u591a\u6761\u4ef6\u7528\u00a0&amp;\u00a0\/\u00a0|\u00a0\u800c\u975e\u00a0and\u00a0\/\u00a0or&#xff1a;Python \u5173\u952e\u5b57\u5728\u8868\u8fbe\u5f0f\u91cc\u4e0d\u751f\u6548\u4e14\u4e0d\u62a5\u9519&#xff0c;\u9759\u9ed8\u8fd4\u56de\u9519\u8bef\u7ed3\u679c\u3002<\/li>\n<li>describe()\u00a0\u5bf9\u975e\u6570\u503c\u5217&#xff1a;Polars \u4f1a\u7ed9\u51fa\u7edf\u8ba1\u4f46\u884c\u4e3a\u4e0e Pandas \u4e0d\u540c&#xff0c;\u522b\u6307\u671b NaN \u8ba1\u6570\u3002<\/li>\n<li>to_pandas()\u00a0\u5927\u8868\u8f6c\u6362\u5185\u5b58\u7ffb\u500d&#xff1a;\u80fd\u4fdd\u6301 Polars \u5c31\u4fdd\u6301&#xff1b;\u8f6c\u6362\u540e\u6ce8\u610f Arrow \u4e0e Pandas \u7684 dtype \u6620\u5c04\u3002<\/li>\n<li>\u7248\u672c\u5347\u7ea7\u7834\u574f\u6027\u53d8\u66f4&#xff1a;Polars 1.x \u4e4b\u524d API \u53d8\u52a8\u9891\u7e41&#xff08;\u5982\u00a0groupby\u2192group_by\u3001apply\u2192map_elements&#xff09;&#xff1b;\u8001\u6559\u7a0b\u4ee3\u7801\u76f4\u63a5\u8dd1\u4e0d\u901a\u65f6\u5148\u770b\u7248\u672c\u3002<\/li>\n<hr \/>\n<h3 id=\"8-\u6027\u80fd\u4f18\u5316\u6e05\u535510-\u6761\">8. \u6027\u80fd\u4f18\u5316\u6e05\u5355&#xff08;10 \u6761&#xff09;<\/h3>\n<li>\u9ed8\u8ba4\u8d70 Lazy&#xff1a;\u6240\u6709 ETL \u94fe\u8def\u4ece\u00a0scan_*\u00a0\/\u00a0.lazy()\u00a0\u5f00\u59cb&#xff0c;\u8ba9\u4f18\u5316\u5668\u5e2e\u4f60\u5e72\u6d3b&#xff1b;<\/li>\n<li>\u5217\u88c1\u526a&#xff1a;\u53ea\u00a0select\u00a0\u9700\u8981\u7684\u5217&#xff0c;\u6587\u4ef6\u8bfb\u53d6\u9636\u6bb5\u5c31\u5c11 IO&#xff1b;<\/li>\n<li>\u8c13\u8bcd\u4e0b\u63a8&#xff1a;filter\u00a0\u5199\u5728\u6700\u524d\u9762&#xff08;\u5148\u8fc7\u6ee4\u518d\u8ba1\u7b97&#xff09;&#xff1b;<\/li>\n<li>\u9884\u805a\u5408&#xff1a;\u79d2\u7ea7\u660e\u7ec6\u5148\u00a0group_by &#043; truncate\u00a0\u5230\u5206\u949f\/\u5c0f\u65f6&#xff0c;\u518d\u4e0b\u94bb&#xff1b;<\/li>\n<li>Parquet \u4f18\u5148&#xff1a;\u4e2d\u95f4\u6570\u636e\u4e00\u5f8b Parquet &#043; zstd&#xff0c;\u522b\u7528 CSV \u4e2d\u8f6c&#xff1b;<\/li>\n<li>join_asof\u00a0\u66ff\u4ee3\u81ea\u5199\u5faa\u73af&#xff1a;\u65f6\u5e8f\u5bf9\u9f50\u573a\u666f\u7528\u5b83&#xff0c;\u4e0d\u8981 Python \u5faa\u73af\u9010\u884c\u914d\u5bf9&#xff1b;<\/li>\n<li>\u7528\u00a0pl.len()\u00a0\u8ba1\u6570&#xff1a;agg(pl.len())\u00a0\u6bd4\u00a0agg(pl.col(&#034;x&#034;).count())\u00a0\u8bed\u4e49\u6e05\u6670\u4e14\u5c11\u8bfb\u4e00\u5217&#xff1b;<\/li>\n<li>\u907f\u514d\u00a0map_elements\u00a0\/\u00a0apply&#xff1a;Python UDF \u4f1a\u6253\u7a7f\u6027\u80fd&#xff08;\u6bcf\u884c\u56de\u8c03 Python&#xff09;&#xff0c;\u80fd\u7528\u5185\u7f6e\u8868\u8fbe\u5f0f\u5c31\u7528\u5185\u7f6e\u8868\u8fbe\u5f0f&#xff1b;\u5b9e\u5728\u8981\u81ea\u5b9a\u4e49\u903b\u8f91&#xff0c;\u8003\u8651\u00a0list.eval\u00a0\u6216 Rust \u6269\u5c55&#xff1b;<\/li>\n<li>collect(streaming&#061;True)\u00a0\u6cbb\u7406\u5185\u5b58&#xff1a;\u5927\u6570\u636e\u91cf\u6392\u5e8f\/\u805a\u5408\u89e6\u53d1 spill&#xff0c;\u522b\u786c\u625b\u5185\u5b58&#xff1b;<\/li>\n<li>explain()\u00a0\u68c0\u67e5\u8ba1\u5212&#xff1a;\u4f18\u5316\u5668\u6ca1\u6309\u9884\u671f\u4e0b\u63a8\u65f6&#xff0c;\u516b\u6210\u662f\u5199\u9519\u4e86\u4e0a\u4e0b\u6587&#xff08;\u6bd4\u5982\u5728\u00a0with_columns\u00a0\u91cc\u505a\u4e86\u672c\u5e94\u00a0filter\u00a0\u505a\u7684\u4e8b&#xff09;\u3002<\/li>\n<h3 id=\"9-\u5de5\u4e1a\u6570\u91c7\u843d\u5730\u5efa\u8bae\"><\/h3>\n<hr \/>\n<h3 id=\"10-\u603b\u7ed3\u4e94\u8981\u70b9\">9. \u603b\u7ed3\u4e94\u8981\u70b9<\/h3>\n<li>\u5217\u5f0f\u5b58\u50a8 &#043; \u591a\u7ebf\u7a0b &#043; SIMD\u00a0\u662f Polars \u5feb\u7684\u57fa\u7840&#xff0c;\u4e0d\u662f\u9b54\u6cd5&#xff1b;<\/li>\n<li>\u8868\u8fbe\u5f0f\u7edf\u4e00\u8bed\u6cd5\u00a0\u8ba9\u9009\u3001\u6ee4\u3001\u805a\u3001\u7a97\u53e3\u4e00\u5957\u601d\u7ef4\u8d70\u5929\u4e0b&#xff0c;\u4ee3\u7801\u53ef\u8bfb\u6027\u8fdc\u8d85 Pandas \u7684\u591a\u79cd\u5199\u6cd5&#xff1b;<\/li>\n<li>LazyFrame &#043; \u67e5\u8be2\u4f18\u5316\u5668\u00a0\u662f\u7701\u5185\u5b58\u7684\u94a5\u5319\u2014\u2014\u6574\u68f5\u6811\u4e00\u6b21\u6267\u884c\u3001\u8c13\u8bcd\/\u6295\u5f71\u4e0b\u63a8\u3001\u65e0\u4e2d\u95f4\u5e27&#xff1b;<\/li>\n<li>\u4e25\u683c\u7c7b\u578b &#043; \u663e\u5f0f\u9519\u8bef\u00a0\u662f\u7a33\u7684\u4fdd\u969c\u2014\u2014\u5751\u5728\u7f16\u8bd1\u671f\u66b4\u9732&#xff0c;\u800c\u4e0d\u662f\u7ebf\u4e0a\u9759\u9ed8\u7b97\u9519&#xff1b;<\/li>\n<li>\u5de5\u4e1a\u6570\u91c7\u7684\u6b63\u786e\u59ff\u52bf&#xff1a;\u91c7\u96c6\u7528 C&#043;&#043;\/Go&#xff0c;\u5b58\u50a8\u7528 TDengine\/Kafka&#xff0c;\u5206\u6790\u7528 Polars\u2014\u2014\u628a\u5bf9\u7684\u5de5\u5177\u7528\u5728\u5bf9\u7684\u73af\u8282\u3002<\/li>\n<hr \/>\n<h3 id=\"faq10-\u6761\u901f\u67e5\">FAQ&#xff08;10 \u6761\u901f\u67e5&#xff09;<\/h3>\n<li>Polars \u4f1a\u53d6\u4ee3 Pandas \u5417&#xff1f;\u00a0\u77ed\u671f\u4e0d\u4f1a&#xff1b;\u5b83\u53d6\u4ee3\u7684\u662f\u300cPandas \u625b\u4e0d\u52a8\u5927\u6570\u636e\u91cf\u300d\u7684\u75db\u70b9&#xff0c;\u751f\u6001\u4e92\u8865\u3002<\/li>\n<li>\u9700\u8981\u4f1a Rust \u5417&#xff1f;\u00a0\u4e0d\u9700\u8981&#xff0c;pip \u88c5\u7684\u662f\u7f16\u8bd1\u597d\u7684 wheel\u3002<\/li>\n<li>Lazy \u4e00\u5b9a\u6bd4 Eager \u5feb\u5417&#xff1f;\u00a0\u4e0d\u4e00\u5b9a&#xff1b;\u4f46 Lazy \u7684\u5185\u5b58\u5cf0\u503c\u4e00\u5b9a\u66f4\u4f4e&#xff0c;\u590d\u6742\u94fe\u8def\u901a\u5e38\u66f4\u5feb\u3002<\/li>\n<li>collect(streaming&#061;True)\u00a0\u4f55\u65f6\u751f\u6548&#xff1f;\u00a0\u6392\u5e8f\u3001\u5206\u7ec4\u805a\u5408\u7b49\u7b97\u5b50&#xff1b;\u53d6\u51b3\u4e8e\u64cd\u4f5c\u80fd\u5426\u6d41\u5f0f\u5316&#xff0c;Polars \u4f1a\u81ea\u884c\u51b3\u5b9a\u3002<\/li>\n<li>\u652f\u6301 Windows \u5417&#xff1f;\u00a0\u652f\u6301&#xff0c;\u5b98\u65b9\u53d1\u5e03 win x86_64 wheel\u3002<\/li>\n<li>CSV \u7f16\u7801\u95ee\u9898&#xff1f;\u00a0\u9ed8\u8ba4 UTF-8&#xff1b;GBK \u6587\u4ef6\u5148\u00a0encoding&#061;&#034;gbk&#034;&#xff08;read_csv\u00a0\u652f\u6301&#xff09;\u3002<\/li>\n<li>\u548c DuckDB \u4ec0\u4e48\u5173\u7cfb&#xff1f;\u00a0\u540c\u662f\u67e5\u8be2\u5f15\u64ce\u601d\u8def&#xff0c;DuckDB \u504f SQL\u3001Polars \u504f DataFrame&#xff1b;\u53ef\u4e92\u8f6c&#xff08;pl.from_arrow\u00a0\/ duckdb \u8bfb Arrow&#xff09;\u3002<\/li>\n<li>\u652f\u6301 GPU \u5417&#xff1f;\u00a0\u5b98\u65b9\u6682\u672a\u63d0\u4f9b GPU \u6267\u884c&#xff08;CUDA \u52a0\u901f\u4e0d\u5728\u5f53\u524d\u8def\u7ebf\u56fe\u91cd\u70b9&#xff09;&#xff0c;\u5927\u6570\u636e\u91cf\u5efa\u8bae\u8d70\u5206\u5e03\u5f0f &#043; \u5206\u7247\u5e76\u884c\u3002<\/li>\n<li>\u65f6\u95f4\u5e8f\u5217\u652f\u6301\u5982\u4f55&#xff1f;\u00a0\u6709\u00a0dt.*\u00a0\u5168\u5957\u3001truncate\/round\u3001join_asof\u3001rolling&#xff08;\u6eda\u52a8\u7a97\u53e3&#xff09;&#xff0c;\u65f6\u5e8f\u5206\u6790\u591f\u7528\u3002<\/li>\n<li>\u751f\u4ea7\u73af\u5883\u7a33\u5b9a\u6027&#xff1f;\u00a01.x \u8d77 API \u8d8b\u4e8e\u7a33\u5b9a&#xff0c;\u88ab Snowflake \u7b49\u5382\u5546\u91c7\u7528&#xff08;Polars \u662f Snowflake \u6536\u8d2d\u7684\u4e00\u90e8\u5206&#xff09;&#xff0c;\u793e\u533a\u6d3b\u8dc3\u3002<\/li>\n","protected":false},"excerpt":{"rendered":"<p>1. \u80cc\u666f&#xff1a;\u4e3a\u4ec0\u4e48\u5728Pandas \u5df2\u7ecf\u5f88\u597d\u7528\u7684\u5e74\u4ee3\u8fd8\u8981\u5b66 Polars1.1 \u6570\u636e\u5de5\u7a0b\u5e08\u7684\u4e09\u6b21\u89c9\u9192\u505a\u5de5\u4e1a\u6570\u91c7\u7684\u4eba\u90fd\u4f1a\u7ecf\u5386\u4e09\u4e2a\u9636\u6bb5&#xff1a;\u7b2c\u4e00\u9636\u6bb5&#xff1a;\u6570\u636e\u91cf\u5c0f&#xff0c;pd.read_csv()\u00a0\u4e00\u628a\u68ad&#xff0c;\u51e0\u767e MB \u7684 CSV \u4e5f\u5c31\u7b49\u51e0\u79d2\u3002\u7b2c\u4e8c\u9636\u6bb5&#xff1a;\u70b9\u4f4d\u660e\u7ec6\u8d8a\u6512\u8d8a\u591a\u2014\u2014\u4e00\u53f0 CNC \u6bcf\u79d2 10 \u4e2a\u70b9\u4f4d\u3001200 \u53f0\u8bbe\u5907\u300124 \u5c0f\u65f6\u4e0d\u505c\u673a&#xff0c;\u4e00\u5929\u5c31\u662f\u00a01.7 \u4ebf\u884c\u3002Pandas \u5f00\u59cb\u5185\u5b58\u66b4\u6da8\u3001\u5361\u987f\u3001\u8b66\u544a<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[13178,868,81,206,190],"topic":[],"class_list":["post-117371","post","type-post","status-publish","format-standard","hentry","category-server","tag-1024---","tag-868","tag-python","tag-rust","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python Polars \u9ad8\u6027\u80fd\u6570\u636e\u5904\u7406\u5f15\u64ce\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/117371.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Polars \u9ad8\u6027\u80fd\u6570\u636e\u5904\u7406\u5f15\u64ce\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"1. \u80cc\u666f&#xff1a;\u4e3a\u4ec0\u4e48\u5728Pandas \u5df2\u7ecf\u5f88\u597d\u7528\u7684\u5e74\u4ee3\u8fd8\u8981\u5b66 Polars1.1 \u6570\u636e\u5de5\u7a0b\u5e08\u7684\u4e09\u6b21\u89c9\u9192\u505a\u5de5\u4e1a\u6570\u91c7\u7684\u4eba\u90fd\u4f1a\u7ecf\u5386\u4e09\u4e2a\u9636\u6bb5&#xff1a;\u7b2c\u4e00\u9636\u6bb5&#xff1a;\u6570\u636e\u91cf\u5c0f&#xff0c;pd.read_csv()\u00a0\u4e00\u628a\u68ad&#xff0c;\u51e0\u767e MB \u7684 CSV \u4e5f\u5c31\u7b49\u51e0\u79d2\u3002\u7b2c\u4e8c\u9636\u6bb5&#xff1a;\u70b9\u4f4d\u660e\u7ec6\u8d8a\u6512\u8d8a\u591a\u2014\u2014\u4e00\u53f0 CNC \u6bcf\u79d2 10 \u4e2a\u70b9\u4f4d\u3001200 \u53f0\u8bbe\u5907\u300124 \u5c0f\u65f6\u4e0d\u505c\u673a&#xff0c;\u4e00\u5929\u5c31\u662f\u00a01.7 \u4ebf\u884c\u3002Pandas \u5f00\u59cb\u5185\u5b58\u66b4\u6da8\u3001\u5361\u987f\u3001\u8b66\u544a\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/117371.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-10-24T09:48:39+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/117371.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/117371.html\",\"name\":\"Python Polars \u9ad8\u6027\u80fd\u6570\u636e\u5904\u7406\u5f15\u64ce\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-10-24T09:48:39+00:00\",\"dateModified\":\"2026-10-24T09:48:39+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/117371.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/117371.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/117371.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Polars \u9ad8\u6027\u80fd\u6570\u636e\u5904\u7406\u5f15\u64ce\u6df1\u5ea6\u89e3\u6790\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Polars \u9ad8\u6027\u80fd\u6570\u636e\u5904\u7406\u5f15\u64ce\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/117371.html","og_locale":"zh_CN","og_type":"article","og_title":"Python Polars \u9ad8\u6027\u80fd\u6570\u636e\u5904\u7406\u5f15\u64ce\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"1. \u80cc\u666f&#xff1a;\u4e3a\u4ec0\u4e48\u5728Pandas \u5df2\u7ecf\u5f88\u597d\u7528\u7684\u5e74\u4ee3\u8fd8\u8981\u5b66 Polars1.1 \u6570\u636e\u5de5\u7a0b\u5e08\u7684\u4e09\u6b21\u89c9\u9192\u505a\u5de5\u4e1a\u6570\u91c7\u7684\u4eba\u90fd\u4f1a\u7ecf\u5386\u4e09\u4e2a\u9636\u6bb5&#xff1a;\u7b2c\u4e00\u9636\u6bb5&#xff1a;\u6570\u636e\u91cf\u5c0f&#xff0c;pd.read_csv()\u00a0\u4e00\u628a\u68ad&#xff0c;\u51e0\u767e MB \u7684 CSV \u4e5f\u5c31\u7b49\u51e0\u79d2\u3002\u7b2c\u4e8c\u9636\u6bb5&#xff1a;\u70b9\u4f4d\u660e\u7ec6\u8d8a\u6512\u8d8a\u591a\u2014\u2014\u4e00\u53f0 CNC \u6bcf\u79d2 10 \u4e2a\u70b9\u4f4d\u3001200 \u53f0\u8bbe\u5907\u300124 \u5c0f\u65f6\u4e0d\u505c\u673a&#xff0c;\u4e00\u5929\u5c31\u662f\u00a01.7 \u4ebf\u884c\u3002Pandas \u5f00\u59cb\u5185\u5b58\u66b4\u6da8\u3001\u5361\u987f\u3001\u8b66\u544a","og_url":"https:\/\/www.wsisp.com\/helps\/117371.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-10-24T09:48:39+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"10 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/117371.html","url":"https:\/\/www.wsisp.com\/helps\/117371.html","name":"Python Polars \u9ad8\u6027\u80fd\u6570\u636e\u5904\u7406\u5f15\u64ce\u6df1\u5ea6\u89e3\u6790 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-10-24T09:48:39+00:00","dateModified":"2026-10-24T09:48:39+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/117371.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/117371.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/117371.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Python Polars \u9ad8\u6027\u80fd\u6570\u636e\u5904\u7406\u5f15\u64ce\u6df1\u5ea6\u89e3\u6790"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/117371","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=117371"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/117371\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=117371"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=117371"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=117371"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=117371"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}