{"id":149245,"date":"2024-11-01T14:58:37","date_gmt":"2024-11-01T06:58:37","guid":{"rendered":"https:\/\/server.hk\/cnblog\/149245\/"},"modified":"2024-11-01T14:58:38","modified_gmt":"2024-11-01T06:58:38","slug":"%e6%8c%a8%e8%b8%a2%e9%83%a8%e8%90%bd%e5%9d%90%e8%a8%ba%e7%ac%ac%e4%b8%89%e6%9c%9f%ef%bc%9apython%e5%9c%a8%e5%a4%a7%e6%95%b8%e6%93%9a%e8%99%95%e7%90%86%e4%b8%8a%e7%9a%84%e5%84%aa%e5%8b%a2%e5%88%86","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/149245\/","title":{"rendered":"\u6328\u8e22\u90e8\u843d\u5750\u8a3a\u7b2c\u4e09\u671f\uff1aPython\u5728\u5927\u6578\u64da\u8655\u7406\u4e0a\u7684\u512a\u52e2\u5206\u6790"},"content":{"rendered":"<h1 id=\"%e6%8c%a8%e8%b8%a2%e9%83%a8%e8%90%bd%e5%9d%90%e8%a8%ba%e7%ac%ac%e4%b8%89%e6%9c%9f%ef%bc%9apython%e5%9c%a8%e5%a4%a7%e6%95%b8%e6%93%9a%e8%99%95%e7%90%86%e4%b8%8a%e7%9a%84%e5%84%aa%e5%8b%a2%e5%88%86-niuRwqQWuP\">\u6328\u8e22\u90e8\u843d\u5750\u8a3a\u7b2c\u4e09\u671f\uff1aPython\u5728\u5927\u6578\u64da\u8655\u7406\u4e0a\u7684\u512a\u52e2\u5206\u6790<\/h1>\n<p>\u96a8\u8457\u79d1\u6280\u7684\u8fc5\u901f\u767c\u5c55\uff0c\u5927\u6578\u64da\u5df2\u6210\u70ba\u5404\u884c\u5404\u696d\u7684\u91cd\u8981\u8cc7\u7522\u3002\u4f01\u696d\u5229\u7528\u5927\u6578\u64da\u5206\u6790\u4f86\u7372\u53d6\u6d1e\u5bdf\u3001\u63d0\u5347\u6548\u7387\u548c\u589e\u5f37\u7af6\u722d\u529b\u3002\u5728\u9019\u500b\u904e\u7a0b\u4e2d\uff0cPython\u4f5c\u70ba\u4e00\u7a2e\u9ad8\u6548\u4e14\u6613\u65bc\u5b78\u7fd2\u7684\u7de8\u7a0b\u8a9e\u8a00\uff0c\u9010\u6f38\u6210\u70ba\u5927\u6578\u64da\u8655\u7406\u7684\u9996\u9078\u5de5\u5177\u4e4b\u4e00\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0ePython\u5728\u5927\u6578\u64da\u8655\u7406\u4e0a\u7684\u512a\u52e2\u3002<\/p>\n<h2 id=\"1-%e7%b0%a1%e5%96%ae%e6%98%93%e5%ad%b8%e7%9a%84%e8%aa%9e%e6%b3%95-niuRwqQWuP\">1. \u7c21\u55ae\u6613\u5b78\u7684\u8a9e\u6cd5<\/h2>\n<p>Python\u7684\u8a9e\u6cd5\u7c21\u6f54\u660e\u77ad\uff0c\u9019\u4f7f\u5f97\u65b0\u624b\u80fd\u5920\u5feb\u901f\u4e0a\u624b\u3002\u8207\u5176\u4ed6\u7de8\u7a0b\u8a9e\u8a00\u76f8\u6bd4\uff0cPython\u7684\u4ee3\u78bc\u66f4\u63a5\u8fd1\u81ea\u7136\u8a9e\u8a00\uff0c\u9019\u964d\u4f4e\u4e86\u5b78\u7fd2\u66f2\u7dda\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u662f\u7528Python\u8b80\u53d6CSV\u6587\u4ef6\u7684\u7c21\u55ae\u4ee3\u78bc\uff1a<\/p>\n<pre><code>import pandas as pd\n\ndata = pd.read_csv('data.csv')\nprint(data.head())<\/code><\/pre>\n<p>\u9019\u6bb5\u4ee3\u78bc\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528Pandas\u5eab\u8f15\u9b06\u5730\u8b80\u53d6\u548c\u986f\u793a\u6578\u64da\uff0c\u986f\u793a\u4e86Python\u5728\u6578\u64da\u8655\u7406\u4e0a\u7684\u76f4\u89c0\u6027\u3002<\/p>\n<h2 id=\"2-%e5%bc%b7%e5%a4%a7%e7%9a%84%e6%95%b8%e6%93%9a%e8%99%95%e7%90%86%e5%ba%ab-niuRwqQWuP\">2. \u5f37\u5927\u7684\u6578\u64da\u8655\u7406\u5eab<\/h2>\n<p>Python\u64c1\u6709\u773e\u591a\u5f37\u5927\u7684\u6578\u64da\u8655\u7406\u5eab\uff0c\u5982Pandas\u3001NumPy\u548cDask\u7b49\u3002\u9019\u4e9b\u5eab\u63d0\u4f9b\u4e86\u9ad8\u6548\u7684\u6578\u64da\u64cd\u4f5c\u548c\u5206\u6790\u529f\u80fd\uff0c\u80fd\u5920\u8655\u7406\u5927\u91cf\u6578\u64da\u3002\u4f8b\u5982\uff0cPandas\u63d0\u4f9b\u4e86DataFrame\u7d50\u69cb\uff0c\u65b9\u4fbf\u7528\u6236\u9032\u884c\u6578\u64da\u6e05\u7406\u548c\u8f49\u63db\uff1a<\/p>\n<pre><code>import pandas as pd\n\n# \u6578\u64da\u6e05\u7406\u793a\u4f8b\ndata = pd.read_csv('data.csv')\ndata.dropna(inplace=True)  # \u522a\u9664\u7f3a\u5931\u503c\ndata['column'] = data['column'].astype(int)  # \u8f49\u63db\u6578\u64da\u985e\u578b<\/code><\/pre>\n<p>\u9019\u4e9b\u5eab\u7684\u5b58\u5728\u4f7f\u5f97Python\u5728\u5927\u6578\u64da\u8655\u7406\u4e0a\u5177\u5099\u4e86\u5f37\u5927\u7684\u80fd\u529b\uff0c\u80fd\u5920\u8f15\u9b06\u61c9\u5c0d\u5404\u7a2e\u6578\u64da\u6311\u6230\u3002<\/p>\n<h2 id=\"3-%e7%a4%be%e7%be%a4%e6%94%af%e6%8c%81%e8%88%87%e8%b3%87%e6%ba%90%e8%b1%90%e5%af%8c-niuRwqQWuP\">3. \u793e\u7fa4\u652f\u6301\u8207\u8cc7\u6e90\u8c50\u5bcc<\/h2>\n<p>Python\u64c1\u6709\u4e00\u500b\u6d3b\u8e8d\u7684\u958b\u767c\u8005\u793e\u7fa4\uff0c\u9019\u610f\u5473\u8457\u7528\u6236\u53ef\u4ee5\u8f15\u9b06\u627e\u5230\u5404\u7a2e\u8cc7\u6e90\u548c\u652f\u6301\u3002\u7121\u8ad6\u662f\u5b98\u65b9\u6587\u6a94\u3001\u8ad6\u58c7\u9084\u662f\u958b\u6e90\u9805\u76ee\uff0cPython\u7684\u793e\u7fa4\u90fd\u63d0\u4f9b\u4e86\u8c50\u5bcc\u7684\u5b78\u7fd2\u6750\u6599\u548c\u5be6\u7528\u5de5\u5177\u3002\u4f8b\u5982\uff0cKaggle\u662f\u4e00\u500b\u6578\u64da\u79d1\u5b78\u7af6\u8cfd\u5e73\u53f0\uff0c\u63d0\u4f9b\u4e86\u5927\u91cf\u7684\u6578\u64da\u96c6\u548c\u7bc4\u4f8b\u4ee3\u78bc\uff0c\u5e6b\u52a9\u7528\u6236\u63d0\u5347\u6280\u80fd\u3002<\/p>\n<h2 id=\"4-%e8%88%87%e5%a4%a7%e6%95%b8%e6%93%9a%e6%8a%80%e8%a1%93%e7%9a%84%e5%85%bc%e5%ae%b9%e6%80%a7-niuRwqQWuP\">4. \u8207\u5927\u6578\u64da\u6280\u8853\u7684\u517c\u5bb9\u6027<\/h2>\n<p>Python\u8207\u591a\u7a2e\u5927\u6578\u64da\u6280\u8853\u517c\u5bb9\uff0c\u5982Hadoop\u3001Spark\u548cHive\u7b49\u3002\u9019\u4f7f\u5f97Python\u80fd\u5920\u5728\u5927\u6578\u64da\u751f\u614b\u7cfb\u7d71\u4e2d\u7121\u7e2b\u96c6\u6210\uff0c\u4e26\u5229\u7528\u9019\u4e9b\u6280\u8853\u7684\u5f37\u5927\u529f\u80fd\u3002\u4f8b\u5982\uff0c\u4f7f\u7528PySpark\u53ef\u4ee5\u8f15\u9b06\u5730\u5728Spark\u4e0a\u9032\u884c\u5927\u898f\u6a21\u6578\u64da\u8655\u7406\uff1a<\/p>\n<pre><code>from pyspark.sql import SparkSession\n\nspark = SparkSession.builder.appName('example').getOrCreate()\ndata = spark.read.csv('data.csv', header=True, inferSchema=True)\ndata.show()<\/code><\/pre>\n<p>\u9019\u6bb5\u4ee3\u78bc\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528PySpark\u8b80\u53d6CSV\u6587\u4ef6\u4e26\u986f\u793a\u6578\u64da\uff0c\u986f\u793a\u4e86Python\u5728\u5927\u6578\u64da\u74b0\u5883\u4e2d\u7684\u9748\u6d3b\u6027\u3002<\/p>\n<h2 id=\"5-%e6%95%b8%e6%93%9a%e5%8f%af%e8%a6%96%e5%8c%96%e8%83%bd%e5%8a%9b-niuRwqQWuP\">5. \u6578\u64da\u53ef\u8996\u5316\u80fd\u529b<\/h2>\n<p>Python\u9084\u64c1\u6709\u5f37\u5927\u7684\u6578\u64da\u53ef\u8996\u5316\u5eab\uff0c\u5982Matplotlib\u548cSeaborn\uff0c\u9019\u4f7f\u5f97\u7528\u6236\u80fd\u5920\u8f15\u9b06\u5730\u5c07\u6578\u64da\u8f49\u5316\u70ba\u53ef\u8996\u5316\u5716\u8868\uff0c\u5f9e\u800c\u66f4\u597d\u5730\u7406\u89e3\u6578\u64da\u3002\u4f8b\u5982\uff0c\u4f7f\u7528Matplotlib\u7e6a\u88fd\u7c21\u55ae\u7684\u6298\u7dda\u5716\uff1a<\/p>\n<pre><code>import matplotlib.pyplot as plt\n\nx = [1, 2, 3, 4, 5]\ny = [2, 3, 5, 7, 11]\n\nplt.plot(x, y)\nplt.title('\u7c21\u55ae\u6298\u7dda\u5716')\nplt.xlabel('X \u8ef8')\nplt.ylabel('Y \u8ef8')\nplt.show()<\/code><\/pre>\n<p>\u9019\u6bb5\u4ee3\u78bc\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528Matplotlib\u5275\u5efa\u4e00\u500b\u7c21\u55ae\u7684\u6298\u7dda\u5716\uff0c\u5e6b\u52a9\u7528\u6236\u66f4\u76f4\u89c0\u5730\u5206\u6790\u6578\u64da\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-niuRwqQWuP\">\u7e3d\u7d50<\/h2>\n<p>\u7e3d\u7684\u4f86\u8aaa\uff0cPython\u5728\u5927\u6578\u64da\u8655\u7406\u4e0a\u5177\u6709\u7c21\u55ae\u6613\u5b78\u7684\u8a9e\u6cd5\u3001\u5f37\u5927\u7684\u6578\u64da\u8655\u7406\u5eab\u3001\u8c50\u5bcc\u7684\u793e\u7fa4\u652f\u6301\u3001\u8207\u5927\u6578\u64da\u6280\u8853\u7684\u517c\u5bb9\u6027\u4ee5\u53ca\u51fa\u8272\u7684\u6578\u64da\u53ef\u8996\u5316\u80fd\u529b\u3002\u9019\u4e9b\u512a\u52e2\u4f7f\u5f97Python\u6210\u70ba\u6578\u64da\u79d1\u5b78\u5bb6\u548c\u5206\u6790\u5e2b\u7684\u9996\u9078\u5de5\u5177\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u8655\u7406\u548c\u5206\u6790\u5927\u6578\u64da\u7684\u4f01\u696d\u4f86\u8aaa\uff0c\u9078\u64c7\u5408\u9069\u7684\u6280\u8853\u57fa\u790e\u8a2d\u65bd\u81f3\u95dc\u91cd\u8981\u3002\u82e5\u60a8\u5c0d\u65bc<code><a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a><\/code>\u6216<code><a href=\"https:\/\/server.hk\">\u96f2\u4f3a\u670d\u5668<\/a><\/code>\u6709\u8208\u8da3\uff0cServer.HK\u63d0\u4f9b\u591a\u7a2e\u89e3\u6c7a\u65b9\u6848\u4ee5\u6eff\u8db3\u60a8\u7684\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u6328\u8e22\u90e8\u843d\u5750\u8a3a\u7b2c\u4e09\u671f\uff0c\u6df1\u5165\u5206\u6790Python\u5728\u5927\u6578\u64da\u8655\u7406\u4e2d\u7684\u512a\u52e2\uff0c\u52a9\u60a8\u638c\u63e1\u6578\u64da\u5206\u6790\u7684\u95dc\u9375\u6280\u8853\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-149245","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/149245","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=149245"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/149245\/revisions"}],"predecessor-version":[{"id":149246,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/149245\/revisions\/149246"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=149245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=149245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=149245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}