{"id":969116,"date":"2024-12-27T05:13:29","date_gmt":"2024-12-26T21:13:29","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/969116.html"},"modified":"2024-12-27T05:13:32","modified_gmt":"2024-12-26T21:13:32","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e7%a8%8b%e5%ba%8f%e8%ae%a1%e7%ae%97","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/969116.html","title":{"rendered":"\u5982\u4f55\u7528python\u7a0b\u5e8f\u8ba1\u7b97"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24183537\/dd238982-4958-4885-9a79-ce471cbf5328.webp\" alt=\"\u5982\u4f55\u7528python\u7a0b\u5e8f\u8ba1\u7b97\" \/><\/p>\n<p><p> <strong>\u7528Python\u7a0b\u5e8f\u8fdb\u884c\u8ba1\u7b97\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u5185\u7f6e\u7684\u6570\u5b66\u8fd0\u7b97\u7b26\u3001\u501f\u52a9Python\u7684\u6570\u5b66\u5e93\u3001\u7f16\u5199\u81ea\u5b9a\u4e49\u51fd\u6570\u3001\u5229\u7528\u6570\u636e\u5904\u7406\u5e93\u5982NumPy\u548cPandas\u7b49\u3002<\/strong> Python\u4ee5\u5176\u7075\u6d3b\u6027\u548c\u5f3a\u5927\u7684\u5e93\u652f\u6301\uff0c\u80fd\u591f\u8fdb\u884c\u7b80\u5355\u5230\u590d\u6742\u7684\u5404\u79cd\u8ba1\u7b97\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528\u8fd9\u4e9b\u65b9\u6cd5\u8fdb\u884c\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u5185\u7f6e\u7684\u6570\u5b66\u8fd0\u7b97\u7b26<\/h3>\n<\/p>\n<p><p>Python\u652f\u6301\u57fa\u672c\u7684\u6570\u5b66\u8fd0\u7b97\u7b26\uff0c\u5982\u52a0\uff08<code>+<\/code>\uff09\u3001\u51cf\uff08<code>-<\/code>\uff09\u3001\u4e58\uff08<code>*<\/code>\uff09\u3001\u9664\uff08<code>\/<\/code>\uff09\u3001\u5e42\uff08<code><\/code>\uff09\u548c\u53d6\u4f59\uff08<code>%<\/code>\uff09\u3002\u8fd9\u4e9b\u8fd0\u7b97\u7b26\u53ef\u4ee5\u76f4\u63a5\u7528\u4e8e\u6570\u503c\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<p><h4>1.1 \u57fa\u672c\u7b97\u672f\u8fd0\u7b97<\/h4>\n<\/p>\n<p><p>Python\u7684\u57fa\u672c\u7b97\u672f\u8fd0\u7b97\u7b26\u975e\u5e38\u76f4\u89c2\u3002\u4f8b\u5982\uff0c\u8ba1\u7b97\u4e24\u4e2a\u6570\u5b57\u7684\u548c\u53ef\u4ee5\u7b80\u5355\u5730\u4f7f\u7528\u52a0\u53f7\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">a = 10<\/p>\n<p>b = 5<\/p>\n<p>sum = a + b  # 15<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7c7b\u4f3c\u5730\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u8fd0\u7b97\u7b26\u8fdb\u884c\u51cf\u6cd5\u3001\u4e58\u6cd5\u3001\u9664\u6cd5\u3001\u5e42\u8fd0\u7b97\u548c\u53d6\u4f59\u8fd0\u7b97\u3002<\/p>\n<\/p>\n<p><h4>1.2 \u8fd0\u7b97\u7b26\u4f18\u5148\u7ea7<\/h4>\n<\/p>\n<p><p>Python\u9075\u5faa\u6570\u5b66\u4e2d\u7684\u6807\u51c6\u8fd0\u7b97\u4f18\u5148\u7ea7\u3002\u4f8b\u5982\uff0c\u4e58\u6cd5\u548c\u9664\u6cd5\u6bd4\u52a0\u6cd5\u548c\u51cf\u6cd5\u4f18\u5148\u7ea7\u66f4\u9ad8\u3002\u53ef\u4ee5\u4f7f\u7528\u62ec\u53f7\u6765\u660e\u786e\u8ba1\u7b97\u987a\u5e8f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">result = (a + b) * 2  # (10 + 5) * 2 = 30<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u501f\u52a9Python\u7684\u6570\u5b66\u5e93<\/h3>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5f3a\u5927\u7684\u6807\u51c6\u5e93<code>math<\/code>\uff0c\u5176\u4e2d\u5305\u542b\u8bb8\u591a\u7528\u4e8e\u6570\u5b66\u8ba1\u7b97\u7684\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><h4>2.1 \u4f7f\u7528<code>math<\/code>\u5e93<\/h4>\n<\/p>\n<p><p>\u8981\u4f7f\u7528<code>math<\/code>\u5e93\u4e2d\u7684\u51fd\u6570\uff0c\u9996\u5148\u9700\u8981\u5bfc\u5165\u8be5\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5e93\u4e2d\u7684\u51fd\u6570\uff0c\u4f8b\u5982\u8ba1\u7b97\u5e73\u65b9\u6839\u3001\u5bf9\u6570\u3001\u4e09\u89d2\u51fd\u6570\u7b49\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">sqrt_value = math.sqrt(16)  # 4.0<\/p>\n<p>log_value = math.log(10)    # 2.302585092994046<\/p>\n<p>cos_value = math.cos(math.pi \/ 4)  # 0.7071067811865476<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2.2 \u5e38\u7528\u7684\u6570\u5b66\u51fd\u6570<\/h4>\n<\/p>\n<p><p><code>math<\/code>\u5e93\u4e2d\u8fd8\u6709\u8bb8\u591a\u5176\u4ed6\u6709\u7528\u7684\u51fd\u6570\uff0c\u5982\uff1a<\/p>\n<\/p>\n<ul>\n<li><code>math.factorial(n)<\/code>\uff1a\u8ba1\u7b97n\u7684\u9636\u4e58\u3002<\/li>\n<li><code>math.gcd(a, b)<\/code>\uff1a\u8ba1\u7b97a\u548cb\u7684\u6700\u5927\u516c\u7ea6\u6570\u3002<\/li>\n<li><code>math.pow(x, y)<\/code>\uff1a\u8ba1\u7b97x\u7684y\u6b21\u5e42\u3002<\/li>\n<\/ul>\n<p><h3>\u4e09\u3001\u7f16\u5199\u81ea\u5b9a\u4e49\u51fd\u6570<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u66f4\u590d\u6742\u7684\u8ba1\u7b97\uff0c\u60a8\u53ef\u4ee5\u7f16\u5199\u81ea\u5df1\u7684\u51fd\u6570\u6765\u5b9e\u73b0\u3002<\/p>\n<\/p>\n<p><h4>3.1 \u81ea\u5b9a\u4e49\u51fd\u6570\u793a\u4f8b<\/h4>\n<\/p>\n<p><p>\u5047\u8bbe\u9700\u8981\u8ba1\u7b97\u4e00\u4e2a\u5217\u8868\u4e2d\u6240\u6709\u6570\u7684\u5e73\u5747\u503c\uff0c\u53ef\u4ee5\u7f16\u5199\u5982\u4e0b\u51fd\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def calculate_average(numbers):<\/p>\n<p>    total = sum(numbers)<\/p>\n<p>    count = len(numbers)<\/p>\n<p>    average = total \/ count<\/p>\n<p>    return average<\/p>\n<p>numbers = [1, 2, 3, 4, 5]<\/p>\n<p>average_value = calculate_average(numbers)  # 3.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3.2 \u53c2\u6570\u4f20\u9012\u548c\u8fd4\u56de\u503c<\/h4>\n<\/p>\n<p><p>\u81ea\u5b9a\u4e49\u51fd\u6570\u53ef\u4ee5\u63a5\u53d7\u591a\u4e2a\u53c2\u6570\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u6216\u591a\u4e2a\u7ed3\u679c\u3002\u4e86\u89e3\u5982\u4f55\u4f20\u9012\u53c2\u6570\u548c\u63a5\u6536\u8fd4\u56de\u503c\u662f\u7f16\u5199\u6709\u6548\u51fd\u6570\u7684\u5173\u952e\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5229\u7528NumPy\u548cPandas\u8fdb\u884c\u6570\u636e\u8ba1\u7b97<\/h3>\n<\/p>\n<p><p>NumPy\u548cPandas\u662fPython\u4e2d\u4e24\u4e2a\u975e\u5e38\u6d41\u884c\u7684\u5e93\uff0c\u7279\u522b\u9002\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\u548c\u6570\u636e\u5206\u6790\u3002<\/p>\n<\/p>\n<p><h4>4.1 \u4f7f\u7528NumPy\u8fdb\u884c\u6570\u7ec4\u8ba1\u7b97<\/h4>\n<\/p>\n<p><p>NumPy\u63d0\u4f9b\u4e86\u652f\u6301\u591a\u7ef4\u6570\u7ec4\u7684\u5bf9\u8c61\uff0c\u4ee5\u53ca\u5bf9\u6570\u7ec4\u8fdb\u884c\u5feb\u901f\u64cd\u4f5c\u7684\u51fd\u6570\u3002\u8981\u4f7f\u7528NumPy\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5\u5e76\u5bfc\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>array = np.array([1, 2, 3, 4, 5])<\/p>\n<p>mean_value = np.mean(array)  # 3.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>NumPy\u652f\u6301\u8bb8\u591a\u9ad8\u6548\u7684\u6570\u7ec4\u64cd\u4f5c\uff0c\u5982\u77e9\u9635\u4e58\u6cd5\u3001\u6c42\u548c\u3001\u6c42\u79ef\u7b49\u3002<\/p>\n<\/p>\n<p><h4>4.2 \u4f7f\u7528Pandas\u8fdb\u884c\u6570\u636e\u5206\u6790<\/h4>\n<\/p>\n<p><p>Pandas\u63d0\u4f9b\u4e86DataFrame\u548cSeries\u8fd9\u4e24\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u4ee5\u7528\u4e8e\u6570\u636e\u5206\u6790\u548c\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>data = {&#39;numbers&#39;: [1, 2, 3, 4, 5]}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<p>mean_value = df[&#39;numbers&#39;].mean()  # 3.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>Pandas\u7684\u5f3a\u5927\u4e4b\u5904\u5728\u4e8e\u5176\u80fd\u591f\u8f7b\u677e\u5904\u7406\u548c\u5206\u6790\u590d\u6742\u7684\u6570\u636e\u96c6\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u5e94\u7528\u573a\u666f\u4e0e\u5b9e\u8df5\u7ecf\u9a8c<\/h3>\n<\/p>\n<p><h4>5.1 \u79d1\u5b66\u8ba1\u7b97<\/h4>\n<\/p>\n<p><p>Python\u5728\u79d1\u5b66\u8ba1\u7b97\u9886\u57df\u6709\u7740\u5e7f\u6cdb\u7684\u5e94\u7528\u3002\u901a\u8fc7SciPy\u5e93\uff0c\u60a8\u53ef\u4ee5\u89e3\u51b3\u5fae\u5206\u65b9\u7a0b\u3001\u8fdb\u884c\u4fe1\u53f7\u5904\u7406\u548c\u7edf\u8ba1\u5206\u6790\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install scipy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><pre><code class=\"language-python\">from scipy.integrate import quad<\/p>\n<p>result, error = quad(lambda x: x2, 0, 1)  # \u79ef\u5206\u7ed3\u679c\u4e3a1\/3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>5.2 \u6570\u636e\u5206\u6790<\/h4>\n<\/p>\n<p><p>\u5728\u6570\u636e\u5206\u6790\u4e2d\uff0cPython\u5e38\u7528\u4e8e\u5904\u7406\u5927\u6570\u636e\u96c6\u3001\u8fdb\u884c\u7edf\u8ba1\u5efa\u6a21\u548c\u6570\u636e\u53ef\u89c6\u5316\u3002\u7ed3\u5408NumPy\u3001Pandas\u548cMatplotlib\u7b49\u5e93\uff0c\u53ef\u4ee5\u5b9e\u73b0\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install matplotlib<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>df[&#39;numbers&#39;].plot(kind=&#39;bar&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>5.3 <a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a><\/h4>\n<\/p>\n<p><p>Python\u662f\u673a\u5668\u5b66\u4e60\u9886\u57df\u7684\u9996\u9009\u8bed\u8a00\u4e4b\u4e00\u3002\u901a\u8fc7\u5e93\u5982Scikit-learn\u3001TensorFlow\u548cPyTorch\uff0c\u60a8\u53ef\u4ee5\u6784\u5efa\u548c\u8bad\u7ec3\u673a\u5668\u5b66\u4e60\u6a21\u578b\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install scikit-learn<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.linear_model import LinearRegression<\/p>\n<h2><strong>\u521b\u5efa\u7ebf\u6027\u56de\u5f52\u6a21\u578b<\/strong><\/h2>\n<p>model = LinearRegression()<\/p>\n<h2><strong>\u4f7f\u7528\u8bad\u7ec3\u6570\u636e\u62df\u5408\u6a21\u578b<\/strong><\/h2>\n<p>model.fit(X_tr<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n, y_train)<\/p>\n<h2><strong>\u4f7f\u7528\u6d4b\u8bd5\u6570\u636e\u8fdb\u884c\u9884\u6d4b<\/strong><\/h2>\n<p>predictions = model.predict(X_test)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u4f18\u5316\u548c\u6027\u80fd<\/h3>\n<\/p>\n<p><h4>6.1 \u4f7f\u7528Cython\u63d0\u9ad8\u6027\u80fd<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8e\u8ba1\u7b97\u5bc6\u96c6\u578b\u4efb\u52a1\uff0cCython\u53ef\u4ee5\u901a\u8fc7\u5c06Python\u4ee3\u7801\u7f16\u8bd1\u4e3aC\u6765\u63d0\u9ad8\u6027\u80fd\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install cython<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7f16\u5199Cython\u4ee3\u7801\u5e76\u7f16\u8bd1\u4e3aC\u6269\u5c55\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u8ba1\u7b97\u6548\u7387\u3002<\/p>\n<\/p>\n<p><h4>6.2 \u5e76\u884c\u8ba1\u7b97<\/h4>\n<\/p>\n<p><p>Python\u7684\u591a\u7ebf\u7a0b\u548c\u591a\u8fdb\u7a0b\u5e93\u53ef\u4ee5\u7528\u4e8e\u5e76\u884c\u8ba1\u7b97\uff0c\u4ece\u800c\u63d0\u9ad8\u7a0b\u5e8f\u7684\u6027\u80fd\u3002\u5bf9\u4e8eI\/O\u5bc6\u96c6\u578b\u4efb\u52a1\uff0c\u591a\u7ebf\u7a0b\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\uff0c\u800c\u5bf9\u4e8eCPU\u5bc6\u96c6\u578b\u4efb\u52a1\uff0c\u591a\u8fdb\u7a0b\u53ef\u80fd\u66f4\u6709\u6548\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from multiprocessing import Pool<\/p>\n<p>def compute_square(n):<\/p>\n<p>    return n * n<\/p>\n<p>with Pool(5) as p:<\/p>\n<p>    print(p.map(compute_square, [1, 2, 3, 4, 5]))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u603b\u7ed3\u4e0e\u672a\u6765\u5c55\u671b<\/h3>\n<\/p>\n<p><p>Python\u4ee5\u5176\u7b80\u5355\u6027\u548c\u5f3a\u5927\u7684\u5e93\u652f\u6301\uff0c\u6210\u4e3a\u89e3\u51b3\u5404\u7c7b\u8ba1\u7b97\u95ee\u9898\u7684\u7406\u60f3\u9009\u62e9\u3002\u4ece\u57fa\u7840\u7684\u6570\u5b66\u8fd0\u7b97\u5230\u590d\u6742\u7684\u6570\u636e\u5206\u6790\u548c\u673a\u5668\u5b66\u4e60\uff0cPython\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5de5\u5177\u548c\u65b9\u6cd5\u3002\u968f\u7740\u6280\u672f\u7684\u4e0d\u65ad\u53d1\u5c55\uff0cPython\u5728\u8ba1\u7b97\u9886\u57df\u7684\u5e94\u7528\u524d\u666f\u5c06\u66f4\u52a0\u5e7f\u9614\u3002\u901a\u8fc7\u4e0d\u65ad\u5b66\u4e60\u548c\u5b9e\u8df5\uff0c\u60a8\u53ef\u4ee5\u66f4\u597d\u5730\u5229\u7528Python\u8fdb\u884c\u9ad8\u6548\u7684\u8ba1\u7b97\u548c\u6570\u636e\u5206\u6790\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u7528Python\u8fdb\u884c\u57fa\u672c\u7684\u6570\u5b66\u8ba1\u7b97\uff1f<\/strong><br \/>Python\u63d0\u4f9b\u4e86\u591a\u79cd\u5185\u7f6e\u51fd\u6570\u548c\u8fd0\u7b97\u7b26\uff0c\u53ef\u4ee5\u8f7b\u677e\u8fdb\u884c\u6570\u5b66\u8ba1\u7b97\u3002\u5e38\u89c1\u7684\u8fd0\u7b97\u5305\u62ec\u52a0\u6cd5\uff08+\uff09\u3001\u51cf\u6cd5\uff08-\uff09\u3001\u4e58\u6cd5\uff08*\uff09\u3001\u9664\u6cd5\uff08\/\uff09\u7b49\u3002\u6bd4\u5982\uff0c\u4f7f\u7528<code>print(2 + 3)<\/code>\u53ef\u4ee5\u8f93\u51fa5\u3002\u5bf9\u4e8e\u66f4\u590d\u6742\u7684\u8ba1\u7b97\uff0cPython\u7684<code>math<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u6570\u5b66\u51fd\u6570\uff0c\u5982\u5e73\u65b9\u6839\u3001\u4e09\u89d2\u51fd\u6570\u7b49\u3002<\/p>\n<p><strong>Python\u7a0b\u5e8f\u5982\u4f55\u5904\u7406\u6d6e\u70b9\u6570\u548c\u6574\u6570\u7684\u8fd0\u7b97\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u6574\u6570\u548c\u6d6e\u70b9\u6570\u53ef\u4ee5\u76f4\u63a5\u53c2\u4e0e\u8fd0\u7b97\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u8fd0\u7b97\u7ed3\u679c\u7684\u7c7b\u578b\u53ef\u80fd\u4f1a\u6709\u6240\u4e0d\u540c\u3002\u4f8b\u5982\uff0c\u6574\u6570\u4e0e\u6d6e\u70b9\u6570\u76f8\u4e58\u65f6\uff0c\u7ed3\u679c\u4f1a\u81ea\u52a8\u8f6c\u6362\u4e3a\u6d6e\u70b9\u6570\u3002\u8981\u786e\u4fdd\u8ba1\u7b97\u7684\u7cbe\u5ea6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>round()<\/code>\u51fd\u6570\u6765\u63a7\u5236\u5c0f\u6570\u4f4d\u6570\u3002<\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528Python\u8fdb\u884c\u7edf\u8ba1\u8ba1\u7b97\uff1f<\/strong><br \/>Python\u7684<code>statistics<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u7528\u4e8e\u7edf\u8ba1\u5206\u6790\u7684\u51fd\u6570\uff0c\u5982\u5747\u503c\uff08mean\uff09\u3001\u4e2d\u4f4d\u6570\uff08median\uff09\u548c\u4f17\u6570\uff08mode\uff09\u3002\u901a\u8fc7\u5bfc\u5165\u8be5\u6a21\u5757\uff0c\u7528\u6237\u53ef\u4ee5\u5feb\u901f\u5bf9\u4e00\u7ec4\u6570\u636e\u8fdb\u884c\u7edf\u8ba1\u8ba1\u7b97\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>import statistics<\/code>\u548c<code>statistics.mean(data)<\/code>\u5c31\u80fd\u8ba1\u7b97\u51fa\u6570\u636e\u5217\u8868\u7684\u5e73\u5747\u503c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u7528Python\u7a0b\u5e8f\u8fdb\u884c\u8ba1\u7b97\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u5185\u7f6e\u7684\u6570\u5b66\u8fd0\u7b97\u7b26\u3001\u501f\u52a9Python\u7684\u6570\u5b66\u5e93\u3001\u7f16\u5199\u81ea\u5b9a\u4e49\u51fd\u6570\u3001\u5229\u7528\u6570\u636e [&hellip;]","protected":false},"author":3,"featured_media":969125,"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\/969116"}],"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=969116"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/969116\/revisions"}],"predecessor-version":[{"id":969126,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/969116\/revisions\/969126"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/969125"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=969116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=969116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=969116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}