{"id":1180265,"date":"2025-01-15T18:34:41","date_gmt":"2025-01-15T10:34:41","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1180265.html"},"modified":"2025-01-15T18:34:44","modified_gmt":"2025-01-15T10:34:44","slug":"python%e5%a6%82%e4%bd%95%e5%81%9a%e5%88%86%e6%9e%90%e9%a2%84%e6%b5%8b","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1180265.html","title":{"rendered":"python\u5982\u4f55\u505a\u5206\u6790\u9884\u6d4b"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25114435\/d762f97e-d7d9-44f0-91be-a9e2fe1f2d83.webp\" alt=\"python\u5982\u4f55\u505a\u5206\u6790\u9884\u6d4b\" \/><\/p>\n<p><p> Python\u4f5c\u4e3a\u4e00\u79cd\u5f3a\u5927\u4e14\u5e7f\u6cdb\u4f7f\u7528\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c<strong>\u5728\u6570\u636e\u5206\u6790\u3001\u9884\u6d4b\u5efa\u6a21\u65b9\u9762\u6709\u7740\u5f3a\u5927\u7684\u529f\u80fd\u548c\u4e30\u5bcc\u7684\u751f\u6001\u7cfb\u7edf<\/strong>\u3002\u4f7f\u7528Python\u8fdb\u884c\u5206\u6790\u9884\u6d4b\u7684\u4e3b\u8981\u6b65\u9aa4\u5305\u62ec\uff1a\u6570\u636e\u6536\u96c6\u3001\u6570\u636e\u6e05\u6d17\u3001\u6570\u636e\u63a2\u7d22\u6027\u5206\u6790\u3001\u7279\u5f81\u5de5\u7a0b\u3001\u6a21\u578b\u9009\u62e9\u4e0e\u8bad\u7ec3\u3001\u6a21\u578b\u8bc4\u4f30\u4e0e\u4f18\u5316\u3001\u6a21\u578b\u90e8\u7f72\u4e0e\u7ef4\u62a4\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u5e76\u63a2\u8ba8\u5982\u4f55\u4f7f\u7528Python\u7684\u5404\u79cd\u5de5\u5177\u548c\u5e93\u6765\u5b9e\u73b0\u8fd9\u4e9b\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u6570\u636e\u6536\u96c6<\/h3>\n<\/p>\n<p><p>\u6570\u636e\u6536\u96c6\u662f\u6570\u636e\u5206\u6790\u548c\u9884\u6d4b\u5efa\u6a21\u7684\u7b2c\u4e00\u6b65\u3002\u6570\u636e\u53ef\u4ee5\u6765\u81ea\u591a\u79cd\u6765\u6e90\uff0c\u5982\u6570\u636e\u5e93\u3001CSV\u6587\u4ef6\u3001Excel\u6587\u4ef6\u3001API\u63a5\u53e3\u3001\u7f51\u7edc\u722c\u866b\u7b49\u3002Python\u63d0\u4f9b\u4e86\u8bb8\u591a\u5e93\u6765\u65b9\u4fbf\u5730\u6536\u96c6\u548c\u5904\u7406\u8fd9\u4e9b\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4ece\u6570\u636e\u5e93\u6536\u96c6\u6570\u636e<\/h4>\n<\/p>\n<p><p>Python\u7684<code>pandas<\/code>\u5e93\u53ef\u4ee5\u8f7b\u677e\u4ece\u5404\u79cd\u6570\u636e\u5e93\u4e2d\u8bfb\u53d6\u6570\u636e\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>SQLAlchemy<\/code>\u5e93\u53ef\u4ee5\u8fde\u63a5\u5230\u5404\u79cdSQL\u6570\u636e\u5e93\uff0c\u5e76\u4f7f\u7528<code>pandas.read_sql<\/code>\u51fd\u6570\u5c06\u67e5\u8be2\u7ed3\u679c\u76f4\u63a5\u52a0\u8f7d\u5230\u6570\u636e\u6846\u4e2d\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>from sqlalchemy import create_engine<\/p>\n<h2><strong>\u521b\u5efa\u6570\u636e\u5e93\u5f15\u64ce<\/strong><\/h2>\n<p>engine = create_engine(&#39;sqlite:\/\/\/example.db&#39;)<\/p>\n<h2><strong>\u6267\u884cSQL\u67e5\u8be2\u5e76\u8bfb\u53d6\u6570\u636e\u5230\u6570\u636e\u6846<\/strong><\/h2>\n<p>df = pd.read_sql(&#39;SELECT * FROM table_name&#39;, engine)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u4eceCSV\u6216Excel\u6587\u4ef6\u6536\u96c6\u6570\u636e<\/h4>\n<\/p>\n<p><p><code>pandas<\/code>\u5e93\u8fd8\u63d0\u4f9b\u4e86\u76f4\u63a5\u8bfb\u53d6CSV\u548cExcel\u6587\u4ef6\u7684\u529f\u80fd\u3002<\/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>df_csv = pd.read_csv(&#39;data.csv&#39;)<\/p>\n<h2><strong>\u8bfb\u53d6Excel\u6587\u4ef6<\/strong><\/h2>\n<p>df_excel = pd.read_excel(&#39;data.xlsx&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u4eceAPI\u63a5\u53e3\u6536\u96c6\u6570\u636e<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528<code>requests<\/code>\u5e93\u53ef\u4ee5\u65b9\u4fbf\u5730\u4eceAPI\u63a5\u53e3\u83b7\u53d6\u6570\u636e\uff0c\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u6570\u636e\u6846\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>import pandas as pd<\/p>\n<h2><strong>\u53d1\u9001GET\u8bf7\u6c42<\/strong><\/h2>\n<p>response = requests.get(&#39;https:\/\/api.example.com\/data&#39;)<\/p>\n<h2><strong>\u5c06JSON\u54cd\u5e94\u8f6c\u6362\u4e3a\u6570\u636e\u6846<\/strong><\/h2>\n<p>df_api = pd.DataFrame(response.json())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4\u3001\u4ece\u7f51\u7edc\u722c\u866b\u6536\u96c6\u6570\u636e<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528<code>BeautifulSoup<\/code>\u548c<code>Scrapy<\/code>\u7b49\u5e93\u53ef\u4ee5\u4ece\u7f51\u9875\u4e0a\u722c\u53d6\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>from bs4 import BeautifulSoup<\/p>\n<p>import pandas as pd<\/p>\n<h2><strong>\u53d1\u9001GET\u8bf7\u6c42\u5e76\u89e3\u6790HTML<\/strong><\/h2>\n<p>response = requests.get(&#39;https:\/\/www.example.com&#39;)<\/p>\n<p>soup = BeautifulSoup(response.text, &#39;html.parser&#39;)<\/p>\n<h2><strong>\u63d0\u53d6\u6570\u636e\u5e76\u8f6c\u6362\u4e3a\u6570\u636e\u6846<\/strong><\/h2>\n<p>data = []<\/p>\n<p>for item in soup.find_all(&#39;div&#39;, class_=&#39;item&#39;):<\/p>\n<p>    data.append({<\/p>\n<p>        &#39;name&#39;: item.find(&#39;h2&#39;).text,<\/p>\n<p>        &#39;price&#39;: item.find(&#39;span&#39;, class_=&#39;price&#39;).text<\/p>\n<p>    })<\/p>\n<p>df_web = pd.DataFrame(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u6570\u636e\u6e05\u6d17<\/h3>\n<\/p>\n<p><p>\u6570\u636e\u6e05\u6d17\u662f\u786e\u4fdd\u6570\u636e\u8d28\u91cf\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u6570\u636e\u6e05\u6d17\u5305\u62ec\u5904\u7406\u7f3a\u5931\u503c\u3001\u91cd\u590d\u503c\u3001\u5f02\u5e38\u503c\u3001\u6570\u636e\u7c7b\u578b\u8f6c\u6362\u7b49\u3002<code>pandas<\/code>\u5e93\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u6765\u8fdb\u884c\u6570\u636e\u6e05\u6d17\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5904\u7406\u7f3a\u5931\u503c<\/h4>\n<\/p>\n<p><p>\u7f3a\u5931\u503c\u53ef\u4ee5\u4f7f\u7528\u5220\u9664\u3001\u586b\u5145\u6216\u63d2\u503c\u7b49\u65b9\u6cd5\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u5220\u9664\u5305\u542b\u7f3a\u5931\u503c\u7684\u884c<\/strong><\/h2>\n<p>df.dropna(inplace=True)<\/p>\n<h2><strong>\u4f7f\u7528\u7279\u5b9a\u503c\u586b\u5145\u7f3a\u5931\u503c<\/strong><\/h2>\n<p>df.fillna(value={&#39;column_name&#39;: 0}, inplace=True)<\/p>\n<h2><strong>\u4f7f\u7528\u63d2\u503c\u6cd5\u586b\u5145\u7f3a\u5931\u503c<\/strong><\/h2>\n<p>df.interpolate(inplace=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u5904\u7406\u91cd\u590d\u503c<\/h4>\n<\/p>\n<p><p>\u91cd\u590d\u503c\u53ef\u4ee5\u4f7f\u7528\u5220\u9664\u6216\u5408\u5e76\u7b49\u65b9\u6cd5\u5904\u7406\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u5220\u9664\u91cd\u590d\u884c<\/strong><\/h2>\n<p>df.drop_duplicates(inplace=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u5904\u7406\u5f02\u5e38\u503c<\/h4>\n<\/p>\n<p><p>\u5f02\u5e38\u503c\u53ef\u4ee5\u4f7f\u7528\u7edf\u8ba1\u65b9\u6cd5\u6216\u89c6\u89c9\u5316\u65b9\u6cd5\u8fdb\u884c\u68c0\u6d4b\u548c\u5904\u7406\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u4f7f\u7528\u56db\u5206\u4f4d\u8ddd\u6cd5\u68c0\u6d4b\u5f02\u5e38\u503c<\/strong><\/h2>\n<p>Q1 = df[&#39;column_name&#39;].quantile(0.25)<\/p>\n<p>Q3 = df[&#39;column_name&#39;].quantile(0.75)<\/p>\n<p>IQR = Q3 - Q1<\/p>\n<p>outliers = df[(df[&#39;column_name&#39;] &lt; (Q1 - 1.5 * IQR)) | (df[&#39;column_name&#39;] &gt; (Q3 + 1.5 * IQR))]<\/p>\n<h2><strong>\u5220\u9664\u5f02\u5e38\u503c<\/strong><\/h2>\n<p>df = df[~df.isin(outliers)].dropna()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4\u3001\u6570\u636e\u7c7b\u578b\u8f6c\u6362<\/h4>\n<\/p>\n<p><p>\u6570\u636e\u7c7b\u578b\u8f6c\u6362\u662f\u786e\u4fdd\u6570\u636e\u7c7b\u578b\u6b63\u786e\u7684\u91cd\u8981\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u8f6c\u6362\u6570\u636e\u7c7b\u578b<\/strong><\/h2>\n<p>df[&#39;column_name&#39;] = df[&#39;column_name&#39;].astype(float)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u6570\u636e\u63a2\u7d22\u6027\u5206\u6790<\/h3>\n<\/p>\n<p><p>\u6570\u636e\u63a2\u7d22\u6027\u5206\u6790\uff08EDA\uff09\u662f\u4e86\u89e3\u6570\u636e\u5206\u5e03\u3001\u7279\u5f81\u548c\u5173\u7cfb\u7684\u91cd\u8981\u6b65\u9aa4\u3002EDA\u5305\u62ec\u7edf\u8ba1\u63cf\u8ff0\u3001\u6570\u636e\u53ef\u89c6\u5316\u3001\u76f8\u5173\u6027\u5206\u6790\u7b49\u3002<code>pandas<\/code>\u3001<code>matplotlib<\/code>\u3001<code>seaborn<\/code>\u7b49\u5e93\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u6765\u8fdb\u884cEDA\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u7edf\u8ba1\u63cf\u8ff0<\/h4>\n<\/p>\n<p><p>\u7edf\u8ba1\u63cf\u8ff0\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u4e86\u89e3\u6570\u636e\u7684\u57fa\u672c\u5206\u5e03\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u8ba1\u7b97\u57fa\u672c\u7edf\u8ba1\u63cf\u8ff0<\/strong><\/h2>\n<p>df.describe()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u6570\u636e\u53ef\u89c6\u5316<\/h4>\n<\/p>\n<p><p>\u6570\u636e\u53ef\u89c6\u5316\u662f\u7406\u89e3\u6570\u636e\u5206\u5e03\u548c\u5173\u7cfb\u7684\u91cd\u8981\u5de5\u5177\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import seaborn as sns<\/p>\n<h2><strong>\u7ed8\u5236\u76f4\u65b9\u56fe<\/strong><\/h2>\n<p>plt.hist(df[&#39;column_name&#39;])<\/p>\n<p>plt.show()<\/p>\n<h2><strong>\u7ed8\u5236\u6563\u70b9\u56fe<\/strong><\/h2>\n<p>sns.scatterplot(x=&#39;column_x&#39;, y=&#39;column_y&#39;, data=df)<\/p>\n<p>plt.show()<\/p>\n<h2><strong>\u7ed8\u5236\u70ed\u529b\u56fe<\/strong><\/h2>\n<p>sns.heatmap(df.corr(), annot=True, cmap=&#39;coolwarm&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u76f8\u5173\u6027\u5206\u6790<\/h4>\n<\/p>\n<p><p>\u76f8\u5173\u6027\u5206\u6790\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u4e86\u89e3\u7279\u5f81\u4e4b\u95f4\u7684\u5173\u7cfb\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u8ba1\u7b97\u76f8\u5173\u7cfb\u6570<\/strong><\/h2>\n<p>df.corr()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u7279\u5f81\u5de5\u7a0b<\/h3>\n<\/p>\n<p><p>\u7279\u5f81\u5de5\u7a0b\u662f\u63d0\u9ad8\u6a21\u578b\u6027\u80fd\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u7279\u5f81\u5de5\u7a0b\u5305\u62ec\u7279\u5f81\u9009\u62e9\u3001\u7279\u5f81\u63d0\u53d6\u3001\u7279\u5f81\u751f\u6210\u7b49\u3002<code>pandas<\/code>\u3001<code>scikit-learn<\/code>\u7b49\u5e93\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u6765\u8fdb\u884c\u7279\u5f81\u5de5\u7a0b\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u7279\u5f81\u9009\u62e9<\/h4>\n<\/p>\n<p><p>\u7279\u5f81\u9009\u62e9\u662f\u9009\u62e9\u5bf9\u6a21\u578b\u6709\u7528\u7684\u7279\u5f81\u7684\u8fc7\u7a0b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>from sklearn.feature_selection import SelectKBest, chi2<\/p>\n<h2><strong>\u4f7f\u7528\u5361\u65b9\u68c0\u9a8c\u9009\u62e9\u6700\u4f73\u7279\u5f81<\/strong><\/h2>\n<p>X = df.drop(&#39;target&#39;, axis=1)<\/p>\n<p>y = df[&#39;target&#39;]<\/p>\n<p>selector = SelectKBest(chi2, k=10)<\/p>\n<p>X_new = selector.fit_transform(X, y)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u7279\u5f81\u63d0\u53d6<\/h4>\n<\/p>\n<p><p>\u7279\u5f81\u63d0\u53d6\u662f\u4ece\u539f\u59cb\u6570\u636e\u4e2d\u63d0\u53d6\u6709\u7528\u7279\u5f81\u7684\u8fc7\u7a0b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>from sklearn.decomposition import PCA<\/p>\n<h2><strong>\u4f7f\u7528\u4e3b\u6210\u5206\u5206\u6790\u63d0\u53d6\u7279\u5f81<\/strong><\/h2>\n<p>X = df.drop(&#39;target&#39;, axis=1)<\/p>\n<p>pca = PCA(n_components=10)<\/p>\n<p>X_new = pca.fit_transform(X)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u7279\u5f81\u751f\u6210<\/h4>\n<\/p>\n<p><p>\u7279\u5f81\u751f\u6210\u662f\u901a\u8fc7\u6570\u636e\u53d8\u6362\u751f\u6210\u65b0\u7279\u5f81\u7684\u8fc7\u7a0b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u751f\u6210\u591a\u9879\u5f0f\u7279\u5f81<\/strong><\/h2>\n<p>df[&#39;new_feature&#39;] = df[&#39;column_x&#39;] * df[&#39;column_y&#39;]<\/p>\n<h2><strong>\u751f\u6210\u5bf9\u6570\u7279\u5f81<\/strong><\/h2>\n<p>df[&#39;log_feature&#39;] = np.log(df[&#39;column_x&#39;] + 1)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u6a21\u578b\u9009\u62e9\u4e0e\u8bad\u7ec3<\/h3>\n<\/p>\n<p><p>\u6a21\u578b\u9009\u62e9\u4e0e\u8bad\u7ec3\u662f\u6570\u636e\u5206\u6790\u548c\u9884\u6d4b\u5efa\u6a21\u7684\u6838\u5fc3\u6b65\u9aa4\u3002\u5e38\u7528\u7684\u6a21\u578b\u5305\u62ec\u7ebf\u6027\u56de\u5f52\u3001\u51b3\u7b56\u6811\u3001\u968f\u673a\u68ee\u6797\u3001\u652f\u6301\u5411\u91cf\u673a\u3001\u795e\u7ecf\u7f51\u7edc\u7b49\u3002<code>scikit-learn<\/code>\u3001<code>TensorFlow<\/code>\u3001<code>PyTorch<\/code>\u7b49\u5e93\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6a21\u578b\u9009\u62e9\u4e0e\u8bad\u7ec3\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u7ebf\u6027\u56de\u5f52<\/h4>\n<\/p>\n<p><p>\u7ebf\u6027\u56de\u5f52\u662f\u6700\u7b80\u5355\u4e14\u5e7f\u6cdb\u4f7f\u7528\u7684\u56de\u5f52\u6a21\u578b\u4e4b\u4e00\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>from sklearn.model_selection import tr<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n_test_split<\/p>\n<p>from sklearn.linear_model import LinearRegression<\/p>\n<p>from sklearn.metrics import mean_squared_error<\/p>\n<h2><strong>\u51c6\u5907\u6570\u636e<\/strong><\/h2>\n<p>X = df.drop(&#39;target&#39;, axis=1)<\/p>\n<p>y = df[&#39;target&#39;]<\/p>\n<p>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)<\/p>\n<h2><strong>\u8bad\u7ec3\u7ebf\u6027\u56de\u5f52\u6a21\u578b<\/strong><\/h2>\n<p>model = LinearRegression()<\/p>\n<p>model.fit(X_train, y_train)<\/p>\n<h2><strong>\u9884\u6d4b\u5e76\u8bc4\u4f30\u6a21\u578b<\/strong><\/h2>\n<p>y_pred = model.predict(X_test)<\/p>\n<p>mse = mean_squared_error(y_test, y_pred)<\/p>\n<p>print(f&#39;Mean Squared Error: {mse}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u51b3\u7b56\u6811<\/h4>\n<\/p>\n<p><p>\u51b3\u7b56\u6811\u662f\u4e00\u79cd\u7b80\u5355\u4e14\u76f4\u89c2\u7684\u5206\u7c7b\u548c\u56de\u5f52\u6a21\u578b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>from sklearn.model_selection import train_test_split<\/p>\n<p>from sklearn.tree import DecisionTreeClassifier<\/p>\n<p>from sklearn.metrics import accuracy_score<\/p>\n<h2><strong>\u51c6\u5907\u6570\u636e<\/strong><\/h2>\n<p>X = df.drop(&#39;target&#39;, axis=1)<\/p>\n<p>y = df[&#39;target&#39;]<\/p>\n<p>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)<\/p>\n<h2><strong>\u8bad\u7ec3\u51b3\u7b56\u6811\u6a21\u578b<\/strong><\/h2>\n<p>model = DecisionTreeClassifier()<\/p>\n<p>model.fit(X_train, y_train)<\/p>\n<h2><strong>\u9884\u6d4b\u5e76\u8bc4\u4f30\u6a21\u578b<\/strong><\/h2>\n<p>y_pred = model.predict(X_test)<\/p>\n<p>accuracy = accuracy_score(y_test, y_pred)<\/p>\n<p>print(f&#39;Accuracy: {accuracy}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u968f\u673a\u68ee\u6797<\/h4>\n<\/p>\n<p><p>\u968f\u673a\u68ee\u6797\u662f\u57fa\u4e8e\u51b3\u7b56\u6811\u7684\u96c6\u6210\u6a21\u578b\uff0c\u901a\u5e38\u5177\u6709\u66f4\u597d\u7684\u6027\u80fd\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>from sklearn.model_selection import train_test_split<\/p>\n<p>from sklearn.ensemble import RandomForestClassifier<\/p>\n<p>from sklearn.metrics import accuracy_score<\/p>\n<h2><strong>\u51c6\u5907\u6570\u636e<\/strong><\/h2>\n<p>X = df.drop(&#39;target&#39;, axis=1)<\/p>\n<p>y = df[&#39;target&#39;]<\/p>\n<p>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)<\/p>\n<h2><strong>\u8bad\u7ec3\u968f\u673a\u68ee\u6797\u6a21\u578b<\/strong><\/h2>\n<p>model = RandomForestClassifier(n_estimators=100)<\/p>\n<p>model.fit(X_train, y_train)<\/p>\n<h2><strong>\u9884\u6d4b\u5e76\u8bc4\u4f30\u6a21\u578b<\/strong><\/h2>\n<p>y_pred = model.predict(X_test)<\/p>\n<p>accuracy = accuracy_score(y_test, y_pred)<\/p>\n<p>print(f&#39;Accuracy: {accuracy}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4\u3001\u652f\u6301\u5411\u91cf\u673a<\/h4>\n<\/p>\n<p><p>\u652f\u6301\u5411\u91cf\u673a\u662f\u4e00\u79cd\u5f3a\u5927\u7684\u5206\u7c7b\u548c\u56de\u5f52\u6a21\u578b\uff0c\u5c24\u5176\u9002\u7528\u4e8e\u5c0f\u6837\u672c\u548c\u9ad8\u7ef4\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>from sklearn.model_selection import train_test_split<\/p>\n<p>from sklearn.svm import SVC<\/p>\n<p>from sklearn.metrics import accuracy_score<\/p>\n<h2><strong>\u51c6\u5907\u6570\u636e<\/strong><\/h2>\n<p>X = df.drop(&#39;target&#39;, axis=1)<\/p>\n<p>y = df[&#39;target&#39;]<\/p>\n<p>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)<\/p>\n<h2><strong>\u8bad\u7ec3\u652f\u6301\u5411\u91cf\u673a\u6a21\u578b<\/strong><\/h2>\n<p>model = SVC()<\/p>\n<p>model.fit(X_train, y_train)<\/p>\n<h2><strong>\u9884\u6d4b\u5e76\u8bc4\u4f30\u6a21\u578b<\/strong><\/h2>\n<p>y_pred = model.predict(X_test)<\/p>\n<p>accuracy = accuracy_score(y_test, y_pred)<\/p>\n<p>print(f&#39;Accuracy: {accuracy}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>5\u3001\u795e\u7ecf\u7f51\u7edc<\/h4>\n<\/p>\n<p><p>\u795e\u7ecf\u7f51\u7edc\u662f\u8fd1\u5e74\u6765\u6700\u6d41\u884c\u7684<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u6a21\u578b\u4e4b\u4e00\uff0c\u5c24\u5176\u9002\u7528\u4e8e\u590d\u6742\u7684\u975e\u7ebf\u6027\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>from sklearn.model_selection import train_test_split<\/p>\n<p>from tensorflow.keras.models import Sequential<\/p>\n<p>from tensorflow.keras.layers import Dense<\/p>\n<p>from sklearn.metrics import accuracy_score<\/p>\n<h2><strong>\u51c6\u5907\u6570\u636e<\/strong><\/h2>\n<p>X = df.drop(&#39;target&#39;, axis=1)<\/p>\n<p>y = df[&#39;target&#39;]<\/p>\n<p>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)<\/p>\n<h2><strong>\u6784\u5efa\u795e\u7ecf\u7f51\u7edc\u6a21\u578b<\/strong><\/h2>\n<p>model = Sequential()<\/p>\n<p>model.add(Dense(64, activation=&#39;relu&#39;, input_shape=(X_train.shape[1],)))<\/p>\n<p>model.add(Dense(32, activation=&#39;relu&#39;))<\/p>\n<p>model.add(Dense(1, activation=&#39;sigmoid&#39;))<\/p>\n<h2><strong>\u7f16\u8bd1\u548c\u8bad\u7ec3\u6a21\u578b<\/strong><\/h2>\n<p>model.compile(optimizer=&#39;adam&#39;, loss=&#39;binary_crossentropy&#39;, metrics=[&#39;accuracy&#39;])<\/p>\n<p>model.fit(X_train, y_train, epochs=10, batch_size=32, validation_split=0.2)<\/p>\n<h2><strong>\u9884\u6d4b\u5e76\u8bc4\u4f30\u6a21\u578b<\/strong><\/h2>\n<p>y_pred = (model.predict(X_test) &gt; 0.5).astype(int)<\/p>\n<p>accuracy = accuracy_score(y_test, y_pred)<\/p>\n<p>print(f&#39;Accuracy: {accuracy}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u6a21\u578b\u8bc4\u4f30\u4e0e\u4f18\u5316<\/h3>\n<\/p>\n<p><p>\u6a21\u578b\u8bc4\u4f30\u4e0e\u4f18\u5316\u662f\u786e\u4fdd\u6a21\u578b\u6027\u80fd\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u6a21\u578b\u8bc4\u4f30\u5305\u62ec\u4f7f\u7528\u4ea4\u53c9\u9a8c\u8bc1\u3001\u6df7\u6dc6\u77e9\u9635\u3001ROC\u66f2\u7ebf\u7b49\u65b9\u6cd5\u8bc4\u4f30\u6a21\u578b\u6027\u80fd\u3002\u6a21\u578b\u4f18\u5316\u5305\u62ec\u8d85\u53c2\u6570\u8c03\u4f18\u3001\u7279\u5f81\u9009\u62e9\u3001\u6a21\u578b\u96c6\u6210\u7b49\u3002<code>scikit-learn<\/code>\u3001<code>TensorFlow<\/code>\u7b49\u5e93\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u6765\u8fdb\u884c\u6a21\u578b\u8bc4\u4f30\u4e0e\u4f18\u5316\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4ea4\u53c9\u9a8c\u8bc1<\/h4>\n<\/p>\n<p><p>\u4ea4\u53c9\u9a8c\u8bc1\u662f\u8bc4\u4f30\u6a21\u578b\u6027\u80fd\u7684\u5e38\u7528\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6709\u6548\u9632\u6b62\u8fc7\u62df\u5408\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>from sklearn.model_selection import cross_val_score<\/p>\n<p>from sklearn.ensemble import RandomForestClassifier<\/p>\n<h2><strong>\u51c6\u5907\u6570\u636e<\/strong><\/h2>\n<p>X = df.drop(&#39;target&#39;, axis=1)<\/p>\n<p>y = df[&#39;target&#39;]<\/p>\n<h2><strong>\u4ea4\u53c9\u9a8c\u8bc1\u8bc4\u4f30\u6a21\u578b<\/strong><\/h2>\n<p>model = RandomForestClassifier(n_estimators=100)<\/p>\n<p>scores = cross_val_score(model, X, y, cv=5)<\/p>\n<p>print(f&#39;Cross-Validation Accuracy: {scores.mean()}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u6df7\u6dc6\u77e9\u9635<\/h4>\n<\/p>\n<p><p>\u6df7\u6dc6\u77e9\u9635\u662f\u8bc4\u4f30\u5206\u7c7b\u6a21\u578b\u6027\u80fd\u7684\u91cd\u8981\u5de5\u5177\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>from sklearn.model_selection import train_test_split<\/p>\n<p>from sklearn.ensemble import RandomForestClassifier<\/p>\n<p>from sklearn.metrics import confusion_matrix<\/p>\n<h2><strong>\u51c6\u5907\u6570\u636e<\/strong><\/h2>\n<p>X = df.drop(&#39;target&#39;, axis=1)<\/p>\n<p>y = df[&#39;target&#39;]<\/p>\n<p>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)<\/p>\n<h2><strong>\u8bad\u7ec3\u6a21\u578b\u5e76\u9884\u6d4b<\/strong><\/h2>\n<p>model = RandomForestClassifier(n_estimators=100)<\/p>\n<p>model.fit(X_train, y_train)<\/p>\n<p>y_pred = model.predict(X_test)<\/p>\n<h2><strong>\u8ba1\u7b97\u6df7\u6dc6\u77e9\u9635<\/strong><\/h2>\n<p>cm = confusion_matrix(y_test, y_pred)<\/p>\n<p>print(cm)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001ROC\u66f2\u7ebf<\/h4>\n<\/p>\n<p><p>ROC\u66f2\u7ebf\u662f\u8bc4\u4f30\u4e8c\u5206\u7c7b\u6a21\u578b\u6027\u80fd\u7684\u91cd\u8981\u5de5\u5177\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>from sklearn.model_selection import train_test_split<\/p>\n<p>from sklearn.ensemble import RandomForestClassifier<\/p>\n<p>from sklearn.metrics import roc_curve, auc<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u51c6\u5907\u6570\u636e<\/strong><\/h2>\n<p>X = df.drop(&#39;target&#39;, axis=1)<\/p>\n<p>y = df[&#39;target&#39;]<\/p>\n<p>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)<\/p>\n<h2><strong>\u8bad\u7ec3\u6a21\u578b\u5e76\u9884\u6d4b<\/strong><\/h2>\n<p>model = RandomForestClassifier(n_estimators=100)<\/p>\n<p>model.fit(X_train, y_train)<\/p>\n<p>y_pred_proba = model.predict_proba(X_test)[:, 1]<\/p>\n<h2><strong>\u8ba1\u7b97ROC\u66f2\u7ebf<\/strong><\/h2>\n<p>fpr, tpr, thresholds = roc_curve(y_test, y_pred_proba)<\/p>\n<p>roc_auc = auc(fpr, tpr)<\/p>\n<h2><strong>\u7ed8\u5236ROC\u66f2\u7ebf<\/strong><\/h2>\n<p>plt.plot(fpr, tpr, label=f&#39;ROC curve (area = {roc_auc:.2f})&#39;)<\/p>\n<p>plt.plot([0, 1], [0, 1], linestyle=&#39;--&#39;)<\/p>\n<p>plt.xlabel(&#39;False Positive Rate&#39;)<\/p>\n<p>plt.ylabel(&#39;True Positive Rate&#39;)<\/p>\n<p>plt.title(&#39;Receiver Operating Characteristic&#39;)<\/p>\n<p>plt.legend(loc=&#39;lower right&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4\u3001\u8d85\u53c2\u6570\u8c03\u4f18<\/h4>\n<\/p>\n<p><p>\u8d85\u53c2\u6570\u8c03\u4f18\u662f\u63d0\u9ad8\u6a21\u578b\u6027\u80fd\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u5e38\u7528\u7684\u65b9\u6cd5\u5305\u62ec\u7f51\u683c\u641c\u7d22\u548c\u968f\u673a\u641c\u7d22\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>from sklearn.model_selection import train_test_split, GridSearchCV<\/p>\n<p>from sklearn.ensemble import RandomForestClassifier<\/p>\n<h2><strong>\u51c6\u5907\u6570\u636e<\/strong><\/h2>\n<p>X = df.drop(&#39;target&#39;, axis=1)<\/p>\n<p>y = df[&#39;target&#39;]<\/p>\n<p>X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)<\/p>\n<h2><strong>\u7f51\u683c\u641c\u7d22\u8d85\u53c2\u6570\u8c03\u4f18<\/strong><\/h2>\n<p>param_grid = {<\/p>\n<p>    &#39;n_estimators&#39;: [50, 100, 200],<\/p>\n<p>    &#39;max_depth&#39;: [None, 10, 20, 30]<\/p>\n<p>}<\/p>\n<p>grid_search = GridSearchCV(RandomForestClassifier(), param_grid, cv=5, scoring=&#39;accuracy&#39;)<\/p>\n<p>grid_search.fit(X_train, y_train)<\/p>\n<h2><strong>\u8f93\u51fa\u6700\u4f73\u53c2\u6570<\/strong><\/h2>\n<p>print(f&#39;Best Parameters: {grid_search.best_params_}&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u6a21\u578b\u90e8\u7f72\u4e0e\u7ef4\u62a4<\/h3>\n<\/p>\n<p><p>\u6a21\u578b\u90e8\u7f72\u4e0e\u7ef4\u62a4\u662f\u786e\u4fdd\u6a21\u578b\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u7a33\u5b9a\u8fd0\u884c\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u6a21\u578b\u90e8\u7f72\u5305\u62ec\u5c06\u6a21\u578b\u4fdd\u5b58\u4e3a\u6587\u4ef6\u3001\u52a0\u8f7d\u6a21\u578b\u8fdb\u884c\u9884\u6d4b\u3001\u6784\u5efaAPI\u63a5\u53e3\u7b49\u3002\u6a21\u578b\u7ef4\u62a4\u5305\u62ec\u76d1\u63a7\u6a21\u578b\u6027\u80fd\u3001\u5b9a\u671f\u66f4\u65b0\u6a21\u578b\u7b49\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u6a21\u578b\u4fdd\u5b58\u4e0e\u52a0\u8f7d<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528<code>joblib<\/code>\u5e93\u53ef\u4ee5\u65b9\u4fbf\u5730\u4fdd\u5b58\u548c\u52a0\u8f7d\u6a21\u578b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import joblib<\/p>\n<p>from sklearn.ensemble import RandomForestClassifier<\/p>\n<h2><strong>\u8bad\u7ec3\u6a21\u578b<\/strong><\/h2>\n<p>model = RandomForestClassifier(n_estimators=100)<\/p>\n<p>model.fit(X_train, y_train)<\/p>\n<h2><strong>\u4fdd\u5b58\u6a21\u578b<\/strong><\/h2>\n<p>joblib.dump(model, &#39;model.pkl&#39;)<\/p>\n<h2><strong>\u52a0\u8f7d\u6a21\u578b<\/strong><\/h2>\n<p>loaded_model = joblib.load(&#39;model.pkl&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u6784\u5efaAPI\u63a5\u53e3<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528<code>Flask<\/code>\u5e93\u53ef\u4ee5\u65b9\u4fbf\u5730\u6784\u5efaAPI\u63a5\u53e3\uff0c\u5c06\u6a21\u578b\u90e8\u7f72\u4e3aWeb\u670d\u52a1\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from flask import Flask, request, jsonify<\/p>\n<p>import joblib<\/p>\n<h2><strong>\u521b\u5efaFlask\u5e94\u7528<\/strong><\/h2>\n<p>app = Flask(__name__)<\/p>\n<h2><strong>\u52a0\u8f7d\u6a21\u578b<\/strong><\/h2>\n<p>model = joblib.load(&#39;model.pkl&#39;)<\/p>\n<h2><strong>\u5b9a\u4e49\u9884\u6d4b\u63a5\u53e3<\/strong><\/h2>\n<p>@app.route(&#39;\/predict&#39;, methods=[&#39;POST&#39;])<\/p>\n<p>def predict():<\/p>\n<p>    data = request.get_json()<\/p>\n<p>    prediction = model.predict([data[&#39;features&#39;]])<\/p>\n<p>    return jsonify({&#39;prediction&#39;: int(prediction[0])})<\/p>\n<h2><strong>\u8fd0\u884c\u5e94\u7528<\/strong><\/h2>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    app.run(debug=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u76d1\u63a7\u6a21\u578b\u6027\u80fd<\/h4>\n<\/p>\n<p><p>\u76d1\u63a7\u6a21\u578b\u6027\u80fd\u662f\u786e\u4fdd\u6a21\u578b\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u7a33\u5b9a\u8fd0\u884c\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u53ef\u4ee5<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>Python\u53ef\u4ee5\u7528\u6765\u8fdb\u884c\u54ea\u4e9b\u7c7b\u578b\u7684\u5206\u6790\u9884\u6d4b\uff1f<\/strong><br \/>Python\u652f\u6301\u591a\u79cd\u5206\u6790\u9884\u6d4b\u65b9\u6cd5\uff0c\u5305\u62ec\u65f6\u95f4\u5e8f\u5217\u5206\u6790\u3001\u56de\u5f52\u5206\u6790\u3001\u5206\u7c7b\u9884\u6d4b\u548c\u805a\u7c7b\u5206\u6790\u7b49\u3002\u901a\u8fc7\u4f7f\u7528\u5e93\u5982Pandas\u3001NumPy\u548cScikit-learn\uff0c\u7528\u6237\u53ef\u4ee5\u5904\u7406\u6570\u636e\u3001\u6784\u5efa\u6a21\u578b\u5e76\u8fdb\u884c\u9884\u6d4b\u3002\u4f8b\u5982\uff0c\u65f6\u95f4\u5e8f\u5217\u5206\u6790\u5e38\u7528\u4e8e\u80a1\u7968\u4ef7\u683c\u9884\u6d4b\uff0c\u800c\u56de\u5f52\u5206\u6790\u5219\u9002\u5408\u4e8e\u623f\u4ef7\u9884\u6d4b\u7b49\u573a\u666f\u3002<\/p>\n<p><strong>\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684Python\u5e93\u8fdb\u884c\u9884\u6d4b\u5206\u6790\uff1f<\/strong><br \/>\u5728\u9009\u62e9\u5e93\u65f6\uff0c\u9700\u8981\u8003\u8651\u6570\u636e\u7684\u6027\u8d28\u548c\u5206\u6790\u7684\u76ee\u6807\u3002\u5bf9\u4e8e\u6570\u636e\u6e05\u7406\u548c\u5904\u7406\uff0cPandas\u662f\u9996\u9009\uff1b\u5bf9\u4e8e\u7edf\u8ba1\u5206\u6790\u548c\u53ef\u89c6\u5316\uff0cStatsmodels\u548cMatplotlib\u975e\u5e38\u6709\u6548\uff1b\u800cScikit-learn\u5219\u9002\u5408\u7528\u4e8e\u673a\u5668\u5b66\u4e60\u6a21\u578b\u7684\u6784\u5efa\u548c\u8bc4\u4f30\u3002\u6839\u636e\u9879\u76ee\u9700\u6c42\uff0c\u7528\u6237\u53ef\u4ee5\u7ec4\u5408\u4f7f\u7528\u8fd9\u4e9b\u5e93\u6765\u5b9e\u73b0\u5168\u9762\u7684\u5206\u6790\u9884\u6d4b\u3002<\/p>\n<p><strong>\u8fdb\u884c\u5206\u6790\u9884\u6d4b\u7684\u6b65\u9aa4\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\u8fdb\u884c\u5206\u6790\u9884\u6d4b\u901a\u5e38\u5305\u62ec\u51e0\u4e2a\u5173\u952e\u6b65\u9aa4\uff1a\u6570\u636e\u6536\u96c6\u4e0e\u6e05\u7406\u3001\u63a2\u7d22\u6027\u6570\u636e\u5206\u6790\u3001\u7279\u5f81\u9009\u62e9\u4e0e\u5de5\u7a0b\u3001\u6a21\u578b\u9009\u62e9\u4e0e\u8bad\u7ec3\u3001\u6a21\u578b\u8bc4\u4f30\u4e0e\u8c03\u4f18\uff0c\u4ee5\u53ca\u6700\u7ec8\u7684\u9884\u6d4b\u5b9e\u73b0\u3002\u5728\u6bcf\u4e2a\u6b65\u9aa4\u4e2d\uff0cPython\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5de5\u5177\u548c\u5e93\uff0c\u4ee5\u7b80\u5316\u6d41\u7a0b\u5e76\u63d0\u9ad8\u6548\u7387\u3002\u901a\u8fc7\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u7528\u6237\u53ef\u4ee5\u6784\u5efa\u51fa\u9ad8\u6548\u3001\u51c6\u786e\u7684\u9884\u6d4b\u6a21\u578b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u4f5c\u4e3a\u4e00\u79cd\u5f3a\u5927\u4e14\u5e7f\u6cdb\u4f7f\u7528\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u5728\u6570\u636e\u5206\u6790\u3001\u9884\u6d4b\u5efa\u6a21\u65b9\u9762\u6709\u7740\u5f3a\u5927\u7684\u529f\u80fd\u548c\u4e30\u5bcc\u7684\u751f\u6001\u7cfb\u7edf\u3002\u4f7f\u7528Py [&hellip;]","protected":false},"author":3,"featured_media":1180267,"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\/1180265"}],"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=1180265"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1180265\/revisions"}],"predecessor-version":[{"id":1180268,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1180265\/revisions\/1180268"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1180267"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1180265"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1180265"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1180265"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}