{"id":1017350,"date":"2024-12-27T12:26:24","date_gmt":"2024-12-27T04:26:24","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1017350.html"},"modified":"2024-12-27T12:26:35","modified_gmt":"2024-12-27T04:26:35","slug":"python%e5%a6%82%e4%bd%95%e5%8a%a0%e8%bd%bd%e5%88%b0%e5%86%85%e5%ad%98","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1017350.html","title":{"rendered":"python\u5982\u4f55\u52a0\u8f7d\u5230\u5185\u5b58"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25160250\/d8895e13-304f-4ac0-a732-fd471555db4a.webp\" alt=\"python\u5982\u4f55\u52a0\u8f7d\u5230\u5185\u5b58\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u52a0\u8f7d\u6570\u636e\u5230\u5185\u5b58\u7684\u65b9\u5f0f\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u6570\u636e\u7ed3\u6784\u3001\u4f7f\u7528numpy\u5e93\u3001\u4f7f\u7528pandas\u5e93\u3001\u4ee5\u53ca\u901a\u8fc7\u5185\u5b58\u6620\u5c04\u6587\u4ef6\u8fdb\u884c\u64cd\u4f5c\u3002\u5176\u4e2d\uff0cnumpy\u548cpandas\u662f\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u7684\u5e38\u7528\u5de5\u5177\uff0c\u63d0\u4f9b\u9ad8\u6548\u7684\u5185\u5b58\u4f7f\u7528\u548c\u6570\u636e\u64cd\u4f5c\u65b9\u6cd5\u3002<\/strong> \u5728\u8fd9\u4e9b\u65b9\u5f0f\u4e2d\uff0c\u4f7f\u7528pandas\u5e93\u662f\u975e\u5e38\u666e\u904d\u7684\u4e00\u79cd\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u8f7b\u677e\u5730\u8bfb\u53d6\u5404\u79cd\u683c\u5f0f\u7684\u6570\u636e\u6587\u4ef6\uff0c\u5982CSV\u3001Excel\u3001SQL\u6570\u636e\u5e93\u7b49\uff0c\u5e76\u5c06\u5176\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u8fdb\u884c\u5904\u7406\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u4f7f\u7528pandas\u52a0\u8f7d\u6570\u636e\u5230\u5185\u5b58\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528pandas\u52a0\u8f7d\u6570\u636e\u5230\u5185\u5b58\u7684\u4e00\u4e2a\u5e38\u7528\u65b9\u6cd5\u662f\u4f7f\u7528<code>pandas.read_csv()<\/code>\u51fd\u6570\u8bfb\u53d6CSV\u6587\u4ef6\u3002\u8fd9\u4e2a\u51fd\u6570\u4e0d\u4ec5\u7b80\u5355\u6613\u7528\uff0c\u800c\u4e14\u5728\u5904\u7406\u5927\u6570\u636e\u96c6\u65f6\u8868\u73b0\u51fa\u8272\uff0c\u56e0\u4e3a\u5b83\u652f\u6301\u591a\u7ebf\u7a0b\u8bfb\u53d6\u548c\u5404\u79cd\u4f18\u5316\u9009\u9879\u3002\u901a\u8fc7\u6307\u5b9a\u9002\u5f53\u7684\u53c2\u6570\uff0c\u5982<code>chunksize<\/code>\uff0c\u7528\u6237\u53ef\u4ee5\u9009\u62e9\u9010\u5757\u8bfb\u53d6\u5927\u578b\u6587\u4ef6\uff0c\u8fd9\u6837\u53ef\u4ee5\u6709\u6548\u5730\u63a7\u5236\u5185\u5b58\u4f7f\u7528\uff0c\u907f\u514d\u5360\u7528\u8fc7\u591a\u5185\u5b58\u8d44\u6e90\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u8bfb\u53d6CSV\u6587\u4ef6<\/strong><\/h2>\n<p>data = pd.read_csv(&#39;data.csv&#39;)<\/p>\n<h2><strong>\u67e5\u770b\u6570\u636e\u7684\u524d\u51e0\u884c<\/strong><\/h2>\n<p>print(data.head())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>pd.read_csv()<\/code>\u51fd\u6570\u8bfb\u53d6\u4e00\u4e2a\u540d\u4e3a<code>data.csv<\/code>\u7684\u6587\u4ef6\uff0c\u5e76\u5c06\u5176\u5185\u5bb9\u52a0\u8f7d\u5230\u4e00\u4e2apandas DataFrame\u4e2d\u3002<code>data.head()<\/code>\u51fd\u6570\u7528\u4e8e\u67e5\u770b\u52a0\u8f7d\u6570\u636e\u7684\u524d\u51e0\u884c\uff0c\u8fd9\u6709\u52a9\u4e8e\u5feb\u901f\u68c0\u67e5\u6570\u636e\u662f\u5426\u5df2\u6b63\u786e\u52a0\u8f7d\u3002<\/p>\n<\/p>\n<hr>\n<p><p>\u4e00\u3001\u4f7f\u7528\u5185\u7f6e\u6570\u636e\u7ed3\u6784<\/p>\n<\/p>\n<p><p>Python\u7684\u5185\u7f6e\u6570\u636e\u7ed3\u6784\uff0c\u5982\u5217\u8868\u3001\u5b57\u5178\u548c\u96c6\u5408\uff0c\u901a\u5e38\u7528\u4e8e\u5c06\u5c0f\u89c4\u6a21\u6570\u636e\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u3002\u5b83\u4eec\u7b80\u5355\u6613\u7528\uff0c\u5e76\u4e14\u5bf9\u65b0\u624b\u6765\u8bf4\u975e\u5e38\u53cb\u597d\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528\u5217\u8868<\/strong><\/li>\n<\/ol>\n<p><p>\u5217\u8868\u662fPython\u4e2d\u6700\u5e38\u7528\u7684\u6570\u636e\u7ed3\u6784\u4e4b\u4e00\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u5217\u8868\u5c06\u4e00\u7cfb\u5217\u6570\u636e\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u3002\u5217\u8868\u7684\u4f18\u70b9\u662f\u5b83\u4eec\u662f\u6709\u5e8f\u7684\uff0c\u5e76\u4e14\u5141\u8bb8\u91cd\u590d\u5143\u7d20\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u6f14\u793a\u5982\u4f55\u5c06\u6570\u636e\u52a0\u8f7d\u5230\u5217\u8868\u4e2d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5c06\u6570\u636e\u52a0\u8f7d\u5230\u5217\u8868\u4e2d<\/p>\n<p>data = [1, 2, 3, 4, 5]<\/p>\n<h2><strong>\u8bbf\u95ee\u5217\u8868\u4e2d\u7684\u5143\u7d20<\/strong><\/h2>\n<p>print(data[0])  # \u8f93\u51fa: 1<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a<code>data<\/code>\u7684\u5217\u8868\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u4e00\u4e9b\u6574\u6570\u6570\u636e\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u8bbf\u95ee\u5217\u8868\u4e2d\u7684\u5143\u7d20\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528\u5b57\u5178<\/strong><\/li>\n<\/ol>\n<p><p>\u5b57\u5178\u662f\u53e6\u4e00\u79cd\u5e38\u7528\u7684\u6570\u636e\u7ed3\u6784\uff0c\u7279\u522b\u9002\u5408\u5904\u7406\u952e\u503c\u5bf9\u5f62\u5f0f\u7684\u6570\u636e\u3002\u5b57\u5178\u7684\u4f18\u70b9\u662f\u67e5\u627e\u901f\u5ea6\u5feb\uff0c\u56e0\u4e3a\u5b83\u4eec\u4f7f\u7528\u54c8\u5e0c\u8868\u8fdb\u884c\u6570\u636e\u5b58\u50a8\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u6f14\u793a\u5982\u4f55\u5c06\u6570\u636e\u52a0\u8f7d\u5230\u5b57\u5178\u4e2d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5c06\u6570\u636e\u52a0\u8f7d\u5230\u5b57\u5178\u4e2d<\/p>\n<p>data = {&#39;name&#39;: &#39;Alice&#39;, &#39;age&#39;: 25, &#39;city&#39;: &#39;New York&#39;}<\/p>\n<h2><strong>\u8bbf\u95ee\u5b57\u5178\u4e2d\u7684\u5143\u7d20<\/strong><\/h2>\n<p>print(data[&#39;name&#39;])  # \u8f93\u51fa: Alice<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a<code>data<\/code>\u7684\u5b57\u5178\uff0c\u5176\u4e2d\u5305\u542b\u4e86\u4e00\u4e9b\u952e\u503c\u5bf9\u5f62\u5f0f\u7684\u6570\u636e\u3002\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u952e\u8bbf\u95ee\u5b57\u5178\u4e2d\u7684\u5143\u7d20\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528numpy\u5e93<\/p>\n<\/p>\n<p><p>numpy\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u4e13\u4e3a\u5904\u7406\u5927\u89c4\u6a21\u6570\u7ec4\u548c\u77e9\u9635\u8fd0\u7b97\u800c\u8bbe\u8ba1\u3002\u5b83\u63d0\u4f9b\u4e86\u591a\u79cd\u529f\u80fd\u6765\u9ad8\u6548\u5730\u52a0\u8f7d\u548c\u5904\u7406\u6570\u636e\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u52a0\u8f7d\u6570\u7ec4<\/strong><\/li>\n<\/ol>\n<p><p>numpy\u7684\u4e3b\u8981\u6570\u636e\u7ed3\u6784\u662fndarray\uff08n\u7ef4\u6570\u7ec4\uff09\uff0c\u5b83\u88ab\u8bbe\u8ba1\u7528\u4e8e\u9ad8\u6548\u5730\u5904\u7406\u6570\u503c\u6570\u636e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u6f14\u793a\u5982\u4f55\u4f7f\u7528numpy\u52a0\u8f7d\u6570\u636e\u5230\u5185\u5b58\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2anumpy\u6570\u7ec4<\/strong><\/h2>\n<p>data = np.array([1, 2, 3, 4, 5])<\/p>\n<h2><strong>\u8bbf\u95ee\u6570\u7ec4\u4e2d\u7684\u5143\u7d20<\/strong><\/h2>\n<p>print(data[0])  # \u8f93\u51fa: 1<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>np.array()<\/code>\u51fd\u6570\u521b\u5efa\u4e86\u4e00\u4e2a\u540d\u4e3a<code>data<\/code>\u7684numpy\u6570\u7ec4\u3002\u4e0ePython\u7684\u5217\u8868\u4e0d\u540c\uff0cnumpy\u6570\u7ec4\u5728\u5185\u5b58\u4e2d\u662f\u8fde\u7eed\u5b58\u50a8\u7684\uff0c\u56e0\u6b64\u5b83\u4eec\u5728\u6570\u503c\u8ba1\u7b97\u65b9\u9762\u8868\u73b0\u51fa\u8272\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u8bfb\u53d6\u6587\u4ef6<\/strong><\/li>\n<\/ol>\n<p><p>numpy\u8fd8\u63d0\u4f9b\u4e86\u4e00\u4e9b\u51fd\u6570\u7528\u4e8e\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\u6570\u636e\u3002<code>numpy.loadtxt()<\/code>\u51fd\u6570\u53ef\u4ee5\u4ece\u6587\u672c\u6587\u4ef6\u4e2d\u8bfb\u53d6\u6570\u636e\u5e76\u5c06\u5176\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4ece\u6587\u672c\u6587\u4ef6\u4e2d\u8bfb\u53d6\u6570\u636e<\/p>\n<p>data = np.loadtxt(&#39;data.txt&#39;)<\/p>\n<h2><strong>\u67e5\u770b\u6570\u636e<\/strong><\/h2>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>np.loadtxt()<\/code>\u51fd\u6570\u4ece\u4e00\u4e2a\u540d\u4e3a<code>data.txt<\/code>\u7684\u6587\u4ef6\u4e2d\u8bfb\u53d6\u6570\u636e\uff0c\u5e76\u5c06\u5176\u52a0\u8f7d\u5230\u4e00\u4e2anumpy\u6570\u7ec4\u4e2d\u3002\u8fd9\u4e2a\u65b9\u6cd5\u975e\u5e38\u9002\u5408\u7528\u4e8e\u52a0\u8f7d\u7b80\u5355\u7684\u6587\u672c\u6570\u636e\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528pandas\u5e93<\/p>\n<\/p>\n<p><p>pandas\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u5e93\uff0c\u63d0\u4f9b\u4e86\u9ad8\u5ea6\u4f18\u5316\u7684\u6570\u636e\u7ed3\u6784\u548c\u6570\u636e\u5206\u6790\u5de5\u5177\u3002\u5b83\u7279\u522b\u9002\u5408\u5904\u7406\u8868\u683c\u6570\u636e\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u8bfb\u53d6CSV\u6587\u4ef6<\/strong><\/li>\n<\/ol>\n<p><p>pandas\u6700\u5e38\u7528\u7684\u529f\u80fd\u4e4b\u4e00\u662f\u8bfb\u53d6CSV\u6587\u4ef6\u3002<code>pandas.read_csv()<\/code>\u51fd\u6570\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06CSV\u6587\u4ef6\u4e2d\u7684\u6570\u636e\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u8bfb\u53d6CSV\u6587\u4ef6<\/strong><\/h2>\n<p>data = pd.read_csv(&#39;data.csv&#39;)<\/p>\n<h2><strong>\u67e5\u770b\u6570\u636e\u7684\u524d\u51e0\u884c<\/strong><\/h2>\n<p>print(data.head())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>pd.read_csv()<\/code>\u51fd\u6570\u4ece\u4e00\u4e2a\u540d\u4e3a<code>data.csv<\/code>\u7684\u6587\u4ef6\u4e2d\u8bfb\u53d6\u6570\u636e\uff0c\u5e76\u5c06\u5176\u52a0\u8f7d\u5230\u4e00\u4e2apandas DataFrame\u4e2d\u3002<code>data.head()<\/code>\u51fd\u6570\u7528\u4e8e\u67e5\u770b\u52a0\u8f7d\u6570\u636e\u7684\u524d\u51e0\u884c\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u8bfb\u53d6Excel\u6587\u4ef6<\/strong><\/li>\n<\/ol>\n<p><p>\u9664\u4e86CSV\u6587\u4ef6\uff0cpandas\u8fd8\u652f\u6301\u8bfb\u53d6Excel\u6587\u4ef6\u3002<code>pandas.read_excel()<\/code>\u51fd\u6570\u53ef\u4ee5\u4eceExcel\u6587\u4ef6\u4e2d\u8bfb\u53d6\u6570\u636e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8bfb\u53d6Excel\u6587\u4ef6<\/p>\n<p>data = pd.read_excel(&#39;data.xlsx&#39;)<\/p>\n<h2><strong>\u67e5\u770b\u6570\u636e\u7684\u524d\u51e0\u884c<\/strong><\/h2>\n<p>print(data.head())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>pd.read_excel()<\/code>\u51fd\u6570\u4ece\u4e00\u4e2a\u540d\u4e3a<code>data.xlsx<\/code>\u7684\u6587\u4ef6\u4e2d\u8bfb\u53d6\u6570\u636e\uff0c\u5e76\u5c06\u5176\u52a0\u8f7d\u5230\u4e00\u4e2apandas DataFrame\u4e2d\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u5185\u5b58\u6620\u5c04\u6587\u4ef6<\/p>\n<\/p>\n<p><p>\u5185\u5b58\u6620\u5c04\u6587\u4ef6\u662f\u4e00\u79cd\u5c06\u6587\u4ef6\u5185\u5bb9\u6620\u5c04\u5230\u5185\u5b58\u4e2d\u7684\u6280\u672f\uff0c\u5141\u8bb8\u5e94\u7528\u7a0b\u5e8f\u5728\u5185\u5b58\u4e2d\u76f4\u63a5\u8bbf\u95ee\u6587\u4ef6\u6570\u636e\u3002Python\u7684<code>mmap<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u5bf9\u5185\u5b58\u6620\u5c04\u6587\u4ef6\u7684\u652f\u6301\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u521b\u5efa\u5185\u5b58\u6620\u5c04\u6587\u4ef6<\/strong><\/li>\n<\/ol>\n<p><p>\u5185\u5b58\u6620\u5c04\u6587\u4ef6\u53ef\u4ee5\u7528\u4e8e\u5904\u7406\u975e\u5e38\u5927\u7684\u6587\u4ef6\uff0c\u56e0\u4e3a\u5b83\u4eec\u53ea\u5c06\u6587\u4ef6\u7684\u4e00\u90e8\u5206\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u6f14\u793a\u5982\u4f55\u521b\u5efa\u548c\u4f7f\u7528\u5185\u5b58\u6620\u5c04\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import mmap<\/p>\n<h2><strong>\u6253\u5f00\u6587\u4ef6<\/strong><\/h2>\n<p>with open(&#39;data.txt&#39;, &#39;r+b&#39;) as f:<\/p>\n<p>    # \u521b\u5efa\u5185\u5b58\u6620\u5c04\u6587\u4ef6<\/p>\n<p>    mm = mmap.mmap(f.fileno(), 0)<\/p>\n<p>    # \u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9<\/p>\n<p>    print(mm.readline())<\/p>\n<p>    # \u5173\u95ed\u5185\u5b58\u6620\u5c04\u6587\u4ef6<\/p>\n<p>    mm.close()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u6253\u5f00\u4e86\u4e00\u4e2a\u540d\u4e3a<code>data.txt<\/code>\u7684\u6587\u4ef6\uff0c\u5e76\u521b\u5efa\u4e86\u4e00\u4e2a\u5185\u5b58\u6620\u5c04\u6587\u4ef6\u3002\u7136\u540e\uff0c\u6211\u4eec\u8bfb\u53d6\u6587\u4ef6\u7684\u5185\u5bb9\uff0c\u6700\u540e\u5173\u95ed\u5185\u5b58\u6620\u5c04\u6587\u4ef6\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4fee\u6539\u5185\u5b58\u6620\u5c04\u6587\u4ef6<\/strong><\/li>\n<\/ol>\n<p><p>\u5185\u5b58\u6620\u5c04\u6587\u4ef6\u4e0d\u4ec5\u53ef\u4ee5\u8bfb\u53d6\uff0c\u8fd8\u53ef\u4ee5\u4fee\u6539\u6587\u4ef6\u5185\u5bb9\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6253\u5f00\u6587\u4ef6<\/p>\n<p>with open(&#39;data.txt&#39;, &#39;r+b&#39;) as f:<\/p>\n<p>    # \u521b\u5efa\u5185\u5b58\u6620\u5c04\u6587\u4ef6<\/p>\n<p>    mm = mmap.mmap(f.fileno(), 0)<\/p>\n<p>    # \u4fee\u6539\u6587\u4ef6\u5185\u5bb9<\/p>\n<p>    mm[0:5] = b&#39;Hello&#39;<\/p>\n<p>    # \u5173\u95ed\u5185\u5b58\u6620\u5c04\u6587\u4ef6<\/p>\n<p>    mm.close()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u6253\u5f00\u4e86\u4e00\u4e2a\u540d\u4e3a<code>data.txt<\/code>\u7684\u6587\u4ef6\uff0c\u5e76\u521b\u5efa\u4e86\u4e00\u4e2a\u5185\u5b58\u6620\u5c04\u6587\u4ef6\u3002\u7136\u540e\uff0c\u6211\u4eec\u4fee\u6539\u4e86\u6587\u4ef6\u7684\u524d\u4e94\u4e2a\u5b57\u8282\u4e3a<code>Hello<\/code>\uff0c\u6700\u540e\u5173\u95ed\u5185\u5b58\u6620\u5c04\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u4f7f\u7528\u6570\u636e\u5e93\u52a0\u8f7d\u6570\u636e\u5230\u5185\u5b58<\/p>\n<\/p>\n<p><p>\u5728\u6570\u636e\u5206\u6790\u8fc7\u7a0b\u4e2d\uff0c\u6709\u65f6\u9700\u8981\u4ece\u6570\u636e\u5e93\u4e2d\u52a0\u8f7d\u6570\u636e\u3002Python\u63d0\u4f9b\u4e86\u591a\u79cd\u5e93\u548c\u5de5\u5177\uff0c\u53ef\u4ee5\u8fde\u63a5\u5230\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u5e93\uff0c\u5e76\u5c06\u6570\u636e\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528SQLite<\/strong><\/li>\n<\/ol>\n<p><p>SQLite\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684\u5d4c\u5165\u5f0f\u6570\u636e\u5e93\uff0c\u9002\u5408\u4e8e\u9700\u8981\u5b58\u50a8\u4e2d\u5c0f\u89c4\u6a21\u6570\u636e\u7684\u5e94\u7528\u3002Python\u7684<code>sqlite3<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u5bf9SQLite\u6570\u636e\u5e93\u7684\u652f\u6301\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u6f14\u793a\u5982\u4f55\u4eceSQLite\u6570\u636e\u5e93\u4e2d\u52a0\u8f7d\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sqlite3<\/p>\n<h2><strong>\u8fde\u63a5\u5230SQLite\u6570\u636e\u5e93<\/strong><\/h2>\n<p>conn = sqlite3.connect(&#39;example.db&#39;)<\/p>\n<h2><strong>\u521b\u5efa\u6e38\u6807\u5bf9\u8c61<\/strong><\/h2>\n<p>cur = conn.cursor()<\/p>\n<h2><strong>\u6267\u884c\u67e5\u8be2<\/strong><\/h2>\n<p>cur.execute(&#39;SELECT * FROM users&#39;)<\/p>\n<h2><strong>\u83b7\u53d6\u67e5\u8be2\u7ed3\u679c<\/strong><\/h2>\n<p>data = cur.fetchall()<\/p>\n<h2><strong>\u5173\u95ed\u8fde\u63a5<\/strong><\/h2>\n<p>conn.close()<\/p>\n<h2><strong>\u67e5\u770b\u6570\u636e<\/strong><\/h2>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u8fde\u63a5\u5230\u4e00\u4e2a\u540d\u4e3a<code>example.db<\/code>\u7684SQLite\u6570\u636e\u5e93\uff0c\u5e76\u6267\u884c\u4e86\u4e00\u4e2a\u67e5\u8be2\u4ee5\u83b7\u53d6<code>users<\/code>\u8868\u4e2d\u7684\u6570\u636e\u3002\u67e5\u8be2\u7ed3\u679c\u88ab\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u5b58\u50a8\u5728<code>data<\/code>\u53d8\u91cf\u4e2d\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528pandas\u4e0eSQL\u6570\u636e\u5e93<\/strong><\/li>\n<\/ol>\n<p><p>pandas\u5e93\u63d0\u4f9b\u4e86<code>pandas.read_sql()<\/code>\u51fd\u6570\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u4eceSQL\u6570\u636e\u5e93\u4e2d\u8bfb\u53d6\u6570\u636e\u5e76\u5c06\u5176\u52a0\u8f7d\u5230\u4e00\u4e2aDataFrame\u4e2d\u3002\u8fd9\u5bf9\u4e8e\u9700\u8981\u5728\u5185\u5b58\u4e2d\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u7684\u60c5\u51b5\u975e\u5e38\u6709\u7528\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>import sqlite3<\/p>\n<h2><strong>\u8fde\u63a5\u5230SQLite\u6570\u636e\u5e93<\/strong><\/h2>\n<p>conn = sqlite3.connect(&#39;example.db&#39;)<\/p>\n<h2><strong>\u4f7f\u7528pandas\u8bfb\u53d6\u6570\u636e<\/strong><\/h2>\n<p>data = pd.read_sql(&#39;SELECT * FROM users&#39;, conn)<\/p>\n<h2><strong>\u5173\u95ed\u8fde\u63a5<\/strong><\/h2>\n<p>conn.close()<\/p>\n<h2><strong>\u67e5\u770b\u6570\u636e<\/strong><\/h2>\n<p>print(data.head())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>pandas.read_sql()<\/code>\u51fd\u6570\u4ece<code>example.db<\/code>\u6570\u636e\u5e93\u4e2d\u7684<code>users<\/code>\u8868\u8bfb\u53d6\u6570\u636e\uff0c\u5e76\u5c06\u5176\u52a0\u8f7d\u5230\u4e00\u4e2aDataFrame\u4e2d\u3002\u8fd9\u6837\uff0c\u6211\u4eec\u53ef\u4ee5\u5229\u7528pandas\u7684\u5f3a\u5927\u529f\u80fd\u5bf9\u6570\u636e\u8fdb\u884c\u8fdb\u4e00\u6b65\u5206\u6790\u548c\u5904\u7406\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u4f18\u5316\u5185\u5b58\u4f7f\u7528<\/p>\n<\/p>\n<p><p>\u5728\u52a0\u8f7d\u5927\u6570\u636e\u96c6\u5230\u5185\u5b58\u4e2d\u65f6\uff0c\u4f18\u5316\u5185\u5b58\u4f7f\u7528\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u63d0\u9ad8\u5185\u5b58\u4f7f\u7528\u6548\u7387\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528\u9002\u5f53\u7684\u6570\u636e\u7c7b\u578b<\/strong><\/li>\n<\/ol>\n<p><p>\u9009\u62e9\u5408\u9002\u7684\u6570\u636e\u7c7b\u578b\u53ef\u4ee5\u663e\u8457\u51cf\u5c11\u5185\u5b58\u5360\u7528\u3002pandas\u9ed8\u8ba4\u4f7f\u7528<code>float64<\/code>\u548c<code>int64<\/code>\u7c7b\u578b\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u4f7f\u7528<code>float32<\/code>\u6216<code>int32<\/code>\u6765\u8282\u7701\u5185\u5b58\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u8bfb\u53d6CSV\u6587\u4ef6\uff0c\u5e76\u6307\u5b9a\u6570\u636e\u7c7b\u578b<\/strong><\/h2>\n<p>data = pd.read_csv(&#39;data.csv&#39;, dtype={&#39;column1&#39;: &#39;int32&#39;, &#39;column2&#39;: &#39;float32&#39;})<\/p>\n<h2><strong>\u67e5\u770b\u6570\u636e\u7684\u5185\u5b58\u4f7f\u7528\u60c5\u51b5<\/strong><\/h2>\n<p>print(data.memory_usage(deep=True))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7<code>dtype<\/code>\u53c2\u6570\u6307\u5b9a\u4e86\u6570\u636e\u7c7b\u578b\uff0c\u4ece\u800c\u51cf\u5c11\u4e86\u5185\u5b58\u5360\u7528\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528<code>chunksize<\/code>\u53c2\u6570<\/strong><\/li>\n<\/ol>\n<p><p>\u5f53\u8bfb\u53d6\u975e\u5e38\u5927\u7684\u6587\u4ef6\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>chunksize<\/code>\u53c2\u6570\u9010\u5757\u8bfb\u53d6\u6587\u4ef6\uff0c\u4ee5\u907f\u514d\u4e00\u6b21\u6027\u52a0\u8f7d\u6574\u4e2a\u6587\u4ef6\u5360\u7528\u8fc7\u591a\u5185\u5b58\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f8b\u5b50\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u9010\u5757\u8bfb\u53d6CSV\u6587\u4ef6<\/strong><\/h2>\n<p>for chunk in pd.read_csv(&#39;data.csv&#39;, chunksize=1000):<\/p>\n<p>    # \u5bf9\u6bcf\u4e2a\u5757\u8fdb\u884c\u5904\u7406<\/p>\n<p>    print(chunk.head())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u901a\u8fc7\u8bbe\u7f6e<code>chunksize<\/code>\u53c2\u6570\u4e3a1000\uff0c\u9010\u5757\u8bfb\u53d6CSV\u6587\u4ef6\u3002\u8fd9\u6837\u53ef\u4ee5\u5728\u5904\u7406\u5927\u578b\u6587\u4ef6\u65f6\u6709\u6548\u5730\u63a7\u5236\u5185\u5b58\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><p>\u4e03\u3001\u4f7f\u7528\u5927\u6570\u636e\u6280\u672f<\/p>\n<\/p>\n<p><p>\u5f53\u6570\u636e\u91cf\u975e\u5e38\u5e9e\u5927\uff0c\u4ee5\u81f3\u4e8e\u65e0\u6cd5\u5728\u5355\u53f0\u673a\u5668\u7684\u5185\u5b58\u4e2d\u5904\u7406\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5927\u6570\u636e\u6280\u672f\uff0c\u5982Apache Spark\uff0c\u4ee5\u5206\u5e03\u5f0f\u65b9\u5f0f\u5904\u7406\u6570\u636e\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528PySpark<\/strong><\/li>\n<\/ol>\n<p><p>PySpark\u662fSpark\u7684Python\u63a5\u53e3\uff0c\u63d0\u4f9b\u4e86\u5206\u5e03\u5f0f\u6570\u636e\u5904\u7406\u7684\u80fd\u529b\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u4f8b\u5b50\uff0c\u6f14\u793a\u5982\u4f55\u4f7f\u7528PySpark\u52a0\u8f7d\u548c\u5904\u7406\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from pyspark.sql import SparkSession<\/p>\n<h2><strong>\u521b\u5efaSpark\u4f1a\u8bdd<\/strong><\/h2>\n<p>spark = SparkSession.builder.appName(&#39;Example&#39;).getOrCreate()<\/p>\n<h2><strong>\u8bfb\u53d6CSV\u6587\u4ef6\u5230DataFrame<\/strong><\/h2>\n<p>data = spark.read.csv(&#39;data.csv&#39;, header=True, inferSchema=True)<\/p>\n<h2><strong>\u67e5\u770b\u6570\u636e\u7684\u524d\u51e0\u884c<\/strong><\/h2>\n<p>data.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2aSpark\u4f1a\u8bdd\uff0c\u5e76\u4f7f\u7528<code>read.csv()<\/code>\u65b9\u6cd5\u4eceCSV\u6587\u4ef6\u4e2d\u8bfb\u53d6\u6570\u636e\u5230\u4e00\u4e2aDataFrame\u4e2d\u3002\u8fd9\u79cd\u65b9\u6cd5\u5141\u8bb8\u6211\u4eec\u5728\u5206\u5e03\u5f0f\u73af\u5883\u4e2d\u5904\u7406\u6570\u636e\uff0c\u65e0\u9700\u62c5\u5fc3\u5185\u5b58\u9650\u5236\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528Dask<\/strong><\/li>\n<\/ol>\n<p><p>Dask\u662f\u53e6\u4e00\u4e2a\u7528\u4e8e\u5904\u7406\u5927\u6570\u636e\u96c6\u7684\u5de5\u5177\uff0c\u5b83\u53ef\u4ee5\u5728\u591a\u6838\u673a\u5668\u6216\u96c6\u7fa4\u4e0a\u5e76\u884c\u6267\u884c\u6570\u636e\u5904\u7406\u4efb\u52a1\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f8b\u5b50\uff0c\u6f14\u793a\u5982\u4f55\u4f7f\u7528Dask\u52a0\u8f7d\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import dask.dataframe as dd<\/p>\n<h2><strong>\u8bfb\u53d6CSV\u6587\u4ef6\u5230Dask DataFrame<\/strong><\/h2>\n<p>data = dd.read_csv(&#39;data.csv&#39;)<\/p>\n<h2><strong>\u67e5\u770b\u6570\u636e\u7684\u524d\u51e0\u884c<\/strong><\/h2>\n<p>print(data.head())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>dd.read_csv()<\/code>\u65b9\u6cd5\u4eceCSV\u6587\u4ef6\u4e2d\u8bfb\u53d6\u6570\u636e\u5230\u4e00\u4e2aDask DataFrame\u4e2d\u3002Dask\u53ef\u4ee5\u5728\u540e\u53f0\u81ea\u52a8\u5206\u5272\u6570\u636e\uff0c\u5e76\u5728\u591a\u4e2aCPU\u6838\u5fc3\u4e0a\u5e76\u884c\u5904\u7406\u8fd9\u4e9b\u5206\u5757\u3002<\/p>\n<\/p>\n<p><p>\u516b\u3001\u603b\u7ed3\u4e0e\u5efa\u8bae<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u6709\u591a\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5c06\u6570\u636e\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u6839\u636e\u6570\u636e\u91cf\u548c\u6570\u636e\u7ed3\u6784\u7684\u4e0d\u540c\uff0c\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u975e\u5e38\u91cd\u8981\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177<\/strong><\/li>\n<\/ol>\n<p><p>\u5bf9\u4e8e\u5c0f\u89c4\u6a21\u6570\u636e\uff0cPython\u7684\u5185\u7f6e\u6570\u636e\u7ed3\u6784\uff08\u5982\u5217\u8868\u548c\u5b57\u5178\uff09\u53ef\u80fd\u5df2\u7ecf\u8db3\u591f\u3002\u7136\u800c\uff0c\u5bf9\u4e8e\u66f4\u5927\u89c4\u6a21\u7684\u6570\u636e\uff0c\u4f7f\u7528numpy\u548cpandas\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u5904\u7406\u6548\u7387\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5173\u6ce8\u5185\u5b58\u4f18\u5316<\/strong><\/li>\n<\/ol>\n<p><p>\u5728\u5904\u7406\u5927\u6570\u636e\u96c6\u65f6\uff0c\u5173\u6ce8\u5185\u5b58\u4f18\u5316\u662f\u5173\u952e\u3002\u4f7f\u7528\u9002\u5f53\u7684\u6570\u636e\u7c7b\u578b\u548c\u9010\u5757\u8bfb\u53d6\u6587\u4ef6\u7684\u65b9\u6cd5\u53ef\u4ee5\u5e2e\u52a9\u51cf\u5c11\u5185\u5b58\u5360\u7528\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u5229\u7528\u5927\u6570\u636e\u6280\u672f<\/strong><\/li>\n<\/ol>\n<p><p>\u5f53\u6570\u636e\u91cf\u8d85\u51fa\u5355\u53f0\u673a\u5668\u7684\u5185\u5b58\u5bb9\u91cf\u65f6\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u5927\u6570\u636e\u6280\u672f\uff0c\u5982PySpark\u548cDask\uff0c\u4ee5\u5206\u5e03\u5f0f\u65b9\u5f0f\u5904\u7406\u6570\u636e\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u5408\u7406\u9009\u62e9\u5de5\u5177\u548c\u65b9\u6cd5\uff0c\u6211\u4eec\u53ef\u4ee5\u9ad8\u6548\u5730\u5c06\u6570\u636e\u52a0\u8f7d\u5230\u5185\u5b58\u4e2d\u8fdb\u884c\u5904\u7406\u548c\u5206\u6790\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u6709\u6548\u5730\u52a0\u8f7d\u5927\u578b\u6570\u636e\u96c6\u5230\u5185\u5b58\u4e2d\uff1f<\/strong><br \/>\u5728\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u65f6\uff0c\u4f7f\u7528Pandas\u5e93\u63d0\u4f9b\u7684<code>read_csv()<\/code>\u51fd\u6570\u53ef\u4ee5\u5e2e\u52a9\u4f60\u52a0\u8f7d\u6570\u636e\u5230\u5185\u5b58\u3002\u4e3a\u4e86\u63d0\u9ad8\u6548\u7387\uff0c\u8003\u8651\u4f7f\u7528<code>chunksize<\/code>\u53c2\u6570\uff0c\u8fd9\u6837\u53ef\u4ee5\u5206\u5757\u8bfb\u53d6\u6570\u636e\uff0c\u4ece\u800c\u964d\u4f4e\u5185\u5b58\u5360\u7528\u3002\u6b64\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528Dask\u5e93\uff0c\u5b83\u80fd\u591f\u5904\u7406\u8d85\u51fa\u5185\u5b58\u9650\u5236\u7684\u6570\u636e\u96c6\uff0c\u901a\u8fc7\u61d2\u52a0\u8f7d\u548c\u5e76\u884c\u8ba1\u7b97\u6765\u4f18\u5316\u6027\u80fd\u3002<\/p>\n<p><strong>\u4f7f\u7528Python\u52a0\u8f7d\u6570\u636e\u65f6\uff0c\u5982\u4f55\u786e\u4fdd\u5185\u5b58\u4f7f\u7528\u7684\u4f18\u5316\uff1f<\/strong><br \/>\u5728\u52a0\u8f7d\u6570\u636e\u65f6\uff0c\u9009\u62e9\u5408\u9002\u7684\u6570\u636e\u7c7b\u578b\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>float32<\/code>\u4ee3\u66ff<code>float64<\/code>\uff0c\u6216<code>int32<\/code>\u4ee3\u66ff<code>int64<\/code>\uff0c\u53ef\u4ee5\u663e\u8457\u51cf\u5c11\u5185\u5b58\u5360\u7528\u3002\u6b64\u5916\uff0c\u4f7f\u7528<code>categorical<\/code>\u7c7b\u578b\u5904\u7406\u91cd\u590d\u7684\u5b57\u7b26\u4e32\u6570\u636e\uff0c\u4e5f\u80fd\u6709\u6548\u8282\u7701\u5185\u5b58\u3002\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u63d0\u9ad8\u5185\u5b58\u4f7f\u7528\u6548\u7387\u3002<\/p>\n<p><strong>Python\u52a0\u8f7d\u6570\u636e\u5230\u5185\u5b58\u540e\uff0c\u5982\u4f55\u8fdb\u884c\u6570\u636e\u6e05\u6d17\u548c\u9884\u5904\u7406\uff1f<\/strong><br \/>\u5728\u6570\u636e\u52a0\u8f7d\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528Pandas\u5e93\u7684\u591a\u79cd\u51fd\u6570\u8fdb\u884c\u6570\u636e\u6e05\u6d17\u3002\u5e38\u89c1\u64cd\u4f5c\u5305\u62ec\u53bb\u9664\u7f3a\u5931\u503c<code>dropna()<\/code>\uff0c\u586b\u5145\u7f3a\u5931\u503c<code>fillna()<\/code>\uff0c\u4ee5\u53ca\u5bf9\u6570\u636e\u8fdb\u884c\u53bb\u91cd<code>drop_duplicates()<\/code>\u3002\u6b64\u5916\uff0c\u4f7f\u7528<code>apply()<\/code>\u51fd\u6570\u53ef\u4ee5\u5bf9\u6570\u636e\u8fdb\u884c\u66f4\u590d\u6742\u7684\u8f6c\u6362\u548c\u5904\u7406\uff0c\u4ee5\u4fbf\u4e3a\u540e\u7eed\u5206\u6790\u505a\u51c6\u5907\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u52a0\u8f7d\u6570\u636e\u5230\u5185\u5b58\u7684\u65b9\u5f0f\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528\u5185\u7f6e\u6570\u636e\u7ed3\u6784\u3001\u4f7f\u7528numpy\u5e93\u3001\u4f7f\u7528pandas\u5e93\u3001\u4ee5\u53ca\u901a [&hellip;]","protected":false},"author":3,"featured_media":1017371,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1017350"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1017350"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1017350\/revisions"}],"predecessor-version":[{"id":1017374,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1017350\/revisions\/1017374"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1017371"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1017350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1017350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1017350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}