{"id":983322,"date":"2024-12-27T07:18:29","date_gmt":"2024-12-26T23:18:29","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/983322.html"},"modified":"2024-12-27T07:18:31","modified_gmt":"2024-12-26T23:18:31","slug":"python-%e5%90%84%e7%a7%8d%e5%8c%85%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/983322.html","title":{"rendered":"python \u5404\u79cd\u5305\u5982\u4f55\u4f7f\u7528"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24211416\/ff9cbe33-1368-4400-abd5-d3658492afb6.webp\" alt=\"python \u5404\u79cd\u5305\u5982\u4f55\u4f7f\u7528\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c\u4f7f\u7528\u5404\u79cd\u5305\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3001\u7b80\u5316\u4ee3\u7801\u7f16\u5199\u3001\u589e\u52a0\u7a0b\u5e8f\u7684\u529f\u80fd\u6027\u3002Python\u5305\u7684\u4f7f\u7528\u4e3b\u8981\u5305\u62ec\uff1a\u5b89\u88c5\u5305\u3001\u5bfc\u5165\u5305\u3001\u4f7f\u7528\u5305\u4e2d\u7684\u6a21\u5757\u6216\u51fd\u6570\u3001\u67e5\u770b\u5305\u7684\u6587\u6863\u3001\u7ba1\u7406\u5305\u7684\u4f9d\u8d56\u5173\u7cfb\u3002<\/strong>\u5176\u4e2d\uff0c\u5b89\u88c5\u5305\u662f\u4f7f\u7528Python\u5305\u7684\u7b2c\u4e00\u6b65\uff0c\u53ef\u4ee5\u901a\u8fc7pip\u5de5\u5177\u6765\u5b9e\u73b0\uff1b\u5bfc\u5165\u5305\u662f\u4e3a\u4e86\u5728\u4ee3\u7801\u4e2d\u8c03\u7528\u5305\u7684\u529f\u80fd\uff0c\u901a\u5e38\u4f7f\u7528import\u8bed\u53e5\uff1b\u4f7f\u7528\u5305\u4e2d\u7684\u6a21\u5757\u6216\u51fd\u6570\u6d89\u53ca\u5230\u5177\u4f53\u7684\u7f16\u7a0b\u9700\u6c42\uff1b\u67e5\u770b\u5305\u7684\u6587\u6863\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u66f4\u597d\u5730\u7406\u89e3\u5305\u7684\u529f\u80fd\u53ca\u7528\u6cd5\uff1b\u7ba1\u7406\u5305\u7684\u4f9d\u8d56\u5173\u7cfb\u662f\u4e3a\u4e86\u786e\u4fdd\u7a0b\u5e8f\u7684\u53ef\u7ef4\u62a4\u6027\u548c\u7a33\u5b9a\u6027\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u9762\u7684\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5b89\u88c5Python\u5305<\/p>\n<\/p>\n<p><p>\u5b89\u88c5Python\u5305\u662f\u4f7f\u7528\u5305\u7684\u524d\u63d0\u6761\u4ef6\u3002\u5728Python\u4e2d\uff0c\u6700\u5e38\u7528\u7684\u5305\u7ba1\u7406\u5de5\u5177\u662fpip\u3002\u5b83\u53ef\u4ee5\u65b9\u4fbf\u5730\u4ecePython Package Index (PyPI) \u4e2d\u4e0b\u8f7d\u5e76\u5b89\u88c5\u5404\u79cd\u7b2c\u4e09\u65b9\u5305\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528pip\u5b89\u88c5\u5305<\/strong><\/p>\n<\/p>\n<p><p>\u8981\u5b89\u88c5\u4e00\u4e2aPython\u5305\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<code>pip install \u5305\u540d<\/code>\u3002\u4f8b\u5982\uff0c\u8981\u5b89\u88c5\u4e00\u4e2a\u540d\u4e3arequests\u7684\u5305\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install requests<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u4ecePyPI\u4e0b\u8f7drequests\u5305\u5e76\u5b89\u88c5\u5230\u4f60\u7684Python\u73af\u5883\u4e2d\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u5c31\u53ef\u4ee5\u5728Python\u4ee3\u7801\u4e2d\u5bfc\u5165\u5e76\u4f7f\u7528requests\u5305\u4e86\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5347\u7ea7\u548c\u5378\u8f7d\u5305<\/strong><\/p>\n<\/p>\n<p><p>\u6709\u65f6\u5019\uff0c\u53ef\u80fd\u9700\u8981\u5347\u7ea7\u5df2\u5b89\u88c5\u7684\u5305\u5230\u6700\u65b0\u7248\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip install --upgrade \u5305\u540d<\/code>\u3002\u5982\u679c\u9700\u8981\u5378\u8f7d\u4e00\u4e2a\u4e0d\u518d\u9700\u8981\u7684\u5305\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip uninstall \u5305\u540d<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7ba1\u7406\u5305\u7684\u7248\u672c\u548c\u4f9d\u8d56<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\uff0c\u53ef\u80fd\u4f1a\u6709\u591a\u4e2a\u5305\u76f8\u4e92\u4f9d\u8d56\uff0c\u4e3a\u4e86\u7ba1\u7406\u8fd9\u4e9b\u5305\u7684\u7248\u672c\uff0c\u53ef\u4ee5\u4f7f\u7528<code>requirements.txt<\/code>\u6587\u4ef6\u3002\u8fd9\u4e2a\u6587\u4ef6\u901a\u5e38\u5217\u51fa\u9879\u76ee\u6240\u9700\u7684\u6240\u6709\u5305\u53ca\u5176\u7248\u672c\uff0c\u4f7f\u7528<code>pip install -r requirements.txt<\/code>\u547d\u4ee4\u53ef\u4ee5\u4e00\u6b21\u6027\u5b89\u88c5\u6240\u6709\u5217\u51fa\u7684\u5305\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u5bfc\u5165Python\u5305<\/p>\n<\/p>\n<p><p>\u5728\u5b89\u88c5\u5b8c\u6240\u9700\u7684\u5305\u4e4b\u540e\uff0c\u4e0b\u4e00\u6b65\u5c31\u662f\u5728\u4ee3\u7801\u4e2d\u5bfc\u5165\u8fd9\u4e9b\u5305\u3002Python\u63d0\u4f9b\u4e86\u591a\u79cd\u5bfc\u5165\u65b9\u5f0f\uff0c\u4e3b\u8981\u5305\u62ecimport\u8bed\u53e5\u548cfrom &#8230; import &#8230;\u8bed\u53e5\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528import\u8bed\u53e5<\/strong><\/p>\n<\/p>\n<p><p>\u6700\u5e38\u89c1\u7684\u5bfc\u5165\u65b9\u5f0f\u662f\u4f7f\u7528import\u8bed\u53e5\uff0c\u8fd9\u79cd\u65b9\u5f0f\u5bfc\u5165\u6574\u4e2a\u5305\u6216\u6a21\u5757\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u5bfc\u5165numpy\u5305\u7684\u6240\u6709\u6a21\u5757\uff0c\u6b64\u65f6\u53ef\u4ee5\u4f7f\u7528<code>numpy.\u6a21\u5757\u540d<\/code>\u6765\u8bbf\u95eenumpy\u4e2d\u7684\u6a21\u5757\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528from &#8230; import &#8230;\u8bed\u53e5<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u53ea\u9700\u8981\u5bfc\u5165\u5305\u4e2d\u7684\u67d0\u4e2a\u6a21\u5757\u6216\u51fd\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528from &#8230; import &#8230;\u8bed\u53e5\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from math import sqrt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u53ea\u5bfc\u5165math\u5305\u4e2d\u7684sqrt\u51fd\u6570\uff0c\u6b64\u65f6\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528<code>sqrt()<\/code>\u6765\u8c03\u7528\u8be5\u51fd\u6570\uff0c\u800c\u4e0d\u9700\u8981\u52a0\u4e0a\u5305\u540d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4e3a\u5bfc\u5165\u7684\u5305\u6216\u6a21\u5757\u8bbe\u7f6e\u522b\u540d<\/strong><\/p>\n<\/p>\n<p><p>\u4e3a\u4e86\u7b80\u5316\u4ee3\u7801\u6216\u907f\u514d\u547d\u540d\u51b2\u7a81\uff0c\u53ef\u4ee5\u4e3a\u5bfc\u5165\u7684\u5305\u6216\u6a21\u5757\u8bbe\u7f6e\u522b\u540d\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\uff0c\u5bfc\u5165\u7684pandas\u5305\u53ef\u4ee5\u901a\u8fc7pd\u6765\u5f15\u7528\uff0c\u8fd9\u5728\u4e66\u5199\u4ee3\u7801\u65f6\u53ef\u4ee5\u63d0\u9ad8\u6548\u7387\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u4f7f\u7528Python\u5305\u4e2d\u7684\u6a21\u5757\u548c\u51fd\u6570<\/p>\n<\/p>\n<p><p>\u5b89\u88c5\u5e76\u5bfc\u5165\u5305\u4e4b\u540e\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528\u5305\u4e2d\u7684\u6a21\u5757\u548c\u51fd\u6570\u6765\u5b9e\u73b0\u5177\u4f53\u7684\u529f\u80fd\u3002\u4e0d\u540c\u7684\u5305\u63d0\u4f9b\u4e86\u4e0d\u540c\u7684\u529f\u80fd\uff0c\u4e86\u89e3\u8fd9\u4e9b\u529f\u80fd\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u66f4\u597d\u5730\u4f7f\u7528\u5305\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u67e5\u770b\u5305\u7684\u6587\u6863<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u7b2c\u4e09\u65b9\u5305\u65f6\uff0c\u67e5\u770b\u5305\u7684\u6587\u6863\u662f\u975e\u5e38\u91cd\u8981\u7684\u4e00\u6b65\u3002\u6587\u6863\u901a\u5e38\u8be6\u7ec6\u63cf\u8ff0\u4e86\u5305\u7684\u529f\u80fd\u3001\u6a21\u5757\u3001\u51fd\u6570\u3001\u7c7b\u53ca\u5176\u7528\u6cd5\u3002\u5927\u591a\u6570\u5305\u7684\u6587\u6863\u53ef\u4ee5\u5728\u5176\u5b98\u65b9\u7f51\u7ad9\u6216PyPI\u9875\u9762\u4e0a\u627e\u5230\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u5305\u4e2d\u7684\u6a21\u5757<\/strong><\/p>\n<\/p>\n<p><p>\u4e0d\u540c\u7684\u5305\u63d0\u4f9b\u4e86\u4e0d\u540c\u7684\u6a21\u5757\uff0c\u8fd9\u4e9b\u6a21\u5757\u5c01\u88c5\u4e86\u5305\u7684\u6838\u5fc3\u529f\u80fd\u3002\u8981\u4f7f\u7528\u5305\u4e2d\u7684\u6a21\u5757\uff0c\u53ef\u4ee5\u76f4\u63a5\u5728\u4ee3\u7801\u4e2d\u8c03\u7528\u6a21\u5757\u4e2d\u7684\u51fd\u6570\u6216\u7c7b\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>response = requests.get(&#39;https:\/\/www.example.com&#39;)<\/p>\n<p>print(response.text)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528requests\u5305\u4e2d\u7684get\u51fd\u6570\u6765\u53d1\u9001HTTP GET\u8bf7\u6c42\uff0c\u5e76\u83b7\u53d6\u54cd\u5e94\u5185\u5bb9\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4e86\u89e3\u5305\u7684\u529f\u80fd<\/strong><\/p>\n<\/p>\n<p><p>\u4e0d\u540c\u7684\u5305\u6709\u4e0d\u540c\u7684\u7279\u6027\u548c\u529f\u80fd\uff0c\u4e86\u89e3\u8fd9\u4e9b\u529f\u80fd\u662f\u4f7f\u7528\u5305\u7684\u5173\u952e\u3002\u4f8b\u5982\uff0cnumpy\u5305\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u503c\u8ba1\u7b97\u529f\u80fd\uff0cpandas\u5305\u63d0\u4f9b\u4e86\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u529f\u80fd\uff0cmatplotlib\u5305\u63d0\u4f9b\u4e86\u6570\u636e\u53ef\u89c6\u5316\u529f\u80fd\u3002\u901a\u8fc7\u4e86\u89e3\u8fd9\u4e9b\u529f\u80fd\uff0c\u53ef\u4ee5\u66f4\u597d\u5730\u5229\u7528\u5305\u6765\u89e3\u51b3\u5b9e\u9645\u95ee\u9898\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u7ba1\u7406Python\u5305\u7684\u4f9d\u8d56\u5173\u7cfb<\/p>\n<\/p>\n<p><p>\u5728\u5927\u578b\u9879\u76ee\u4e2d\uff0c\u53ef\u80fd\u4f1a\u7528\u5230\u591a\u4e2a\u5305\uff0c\u8fd9\u4e9b\u5305\u4e4b\u95f4\u53ef\u80fd\u5b58\u5728\u4f9d\u8d56\u5173\u7cfb\u3002\u56e0\u6b64\uff0c\u7ba1\u7406\u5305\u7684\u4f9d\u8d56\u5173\u7cfb\u662f\u786e\u4fdd\u9879\u76ee\u6b63\u5e38\u8fd0\u884c\u7684\u91cd\u8981\u4e00\u73af\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>Python\u7684\u865a\u62df\u73af\u5883\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u9879\u76ee\u521b\u5efa\u72ec\u7acb\u7684\u5305\u5b89\u88c5\u73af\u5883\uff0c\u907f\u514d\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684\u5305\u4f9d\u8d56\u51b2\u7a81\u3002\u53ef\u4ee5\u4f7f\u7528venv\u6a21\u5757\u6765\u521b\u5efa\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python -m venv myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u540e\uff0c\u53ef\u4ee5\u5728\u5176\u4e2d\u5b89\u88c5\u5305\u800c\u4e0d\u5f71\u54cd\u7cfb\u7edf\u7684Python\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528requirements.txt\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u9879\u76ee\u4e2d\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2arequirements.txt\u6587\u4ef6\u6765\u8bb0\u5f55\u9879\u76ee\u6240\u9700\u7684\u6240\u6709\u5305\u53ca\u5176\u7248\u672c\u3002\u8fd9\u6837\u53ef\u4ee5\u65b9\u4fbf\u5176\u4ed6\u5f00\u53d1\u8005\u5728\u9879\u76ee\u4e2d\u5b89\u88c5\u76f8\u540c\u7248\u672c\u7684\u5305\u3002\u4f7f\u7528<code>pip freeze &gt; requirements.txt<\/code>\u547d\u4ee4\u53ef\u4ee5\u751f\u6210\u5f53\u524d\u73af\u5883\u7684requirements.txt\u6587\u4ef6\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u5305\u7ba1\u7406\u5de5\u5177<\/strong><\/p>\n<\/p>\n<p><p>\u9664\u4e86pip\uff0c\u8fd8\u6709\u4e00\u4e9b\u9ad8\u7ea7\u7684\u5305\u7ba1\u7406\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u7ba1\u7406\u5305\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u5982pipenv\u548cpoetry\u3002\u8fd9\u4e9b\u5de5\u5177\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u529f\u80fd\u6765\u7ba1\u7406\u5305\u548c\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u5e38\u7528Python\u5305\u53ca\u5176\u4f7f\u7528<\/p>\n<\/p>\n<p><p>\u4e86\u89e3\u4e00\u4e9b\u5e38\u7528\u7684Python\u5305\u53ca\u5176\u4f7f\u7528\u65b9\u6cd5\uff0c\u53ef\u4ee5\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002\u4ee5\u4e0b\u662f\u51e0\u4e2a\u5e38\u7528\u7684Python\u5305\u53ca\u5176\u4f7f\u7528\u65b9\u6cd5\u7684\u7b80\u8981\u4ecb\u7ecd\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>NumPy<\/strong><\/p>\n<\/p>\n<p><p>NumPy\u662f\u4e00\u4e2a\u7528\u4e8e\u79d1\u5b66\u8ba1\u7b97\u7684\u57fa\u7840\u5305\u3002\u5b83\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u591a\u7ef4\u6570\u7ec4\u5bf9\u8c61\u548c\u4e30\u5bcc\u7684\u6570\u503c\u8ba1\u7b97\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>array = np.array([1, 2, 3])<\/p>\n<p>print(array * 2)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>NumPy\u7684\u6838\u5fc3\u662fndarray\u5bf9\u8c61\uff0c\u5b83\u662f\u4e00\u4e2a\u591a\u7ef4\u6570\u7ec4\uff0c\u53ef\u4ee5\u7528\u4e8e\u9ad8\u6548\u7684\u6570\u503c\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Pandas<\/strong><\/p>\n<\/p>\n<p><p>Pandas\u662f\u4e00\u4e2a\u7528\u4e8e\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u7684\u5305\u3002\u5b83\u63d0\u4f9b\u4e86DataFrame\u548cSeries\u4e24\u79cd\u6570\u636e\u7ed3\u6784\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5904\u7406\u8868\u683c\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>data = {&#39;Name&#39;: [&#39;Alice&#39;, &#39;Bob&#39;], &#39;Age&#39;: [25, 30]}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>Pandas\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6570\u636e\u64cd\u4f5c\u65b9\u6cd5\uff0c\u5982\u6570\u636e\u7b5b\u9009\u3001\u5206\u7ec4\u3001\u805a\u5408\u7b49\uff0c\u662f\u6570\u636e\u5206\u6790\u7684\u91cd\u8981\u5de5\u5177\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Matplotlib<\/strong><\/p>\n<\/p>\n<p><p>Matplotlib\u662f\u4e00\u4e2a\u7528\u4e8e\u6570\u636e\u53ef\u89c6\u5316\u7684\u5305\u3002\u5b83\u63d0\u4f9b\u4e86\u591a\u79cd\u56fe\u8868\u7c7b\u578b\uff0c\u53ef\u4ee5\u7528\u4e8e\u751f\u6210\u9ad8\u8d28\u91cf\u7684\u56fe\u5f62\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>plt.plot([1, 2, 3], [4, 5, 6])<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>Matplotlib\u7684\u6838\u5fc3\u662fpyplot\u6a21\u5757\uff0c\u5b83\u63d0\u4f9b\u4e86\u7c7b\u4f3c\u4e8eMATLAB\u7684\u7ed8\u56fe\u63a5\u53e3\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Requests<\/strong><\/p>\n<\/p>\n<p><p>Requests\u662f\u4e00\u4e2a\u7528\u4e8e\u53d1\u9001HTTP\u8bf7\u6c42\u7684\u5305\u3002\u5b83\u7b80\u5316\u4e86HTTP\u8bf7\u6c42\u7684\u5904\u7406\uff0c\u5e76\u63d0\u4f9b\u4e86\u7b80\u6d01\u7684\u63a5\u53e3\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>response = requests.get(&#39;https:\/\/www.example.com&#39;)<\/p>\n<p>print(response.status_code)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>Requests\u652f\u6301GET\u3001POST\u7b49\u591a\u79cd\u8bf7\u6c42\u65b9\u6cd5\uff0c\u5e76\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u914d\u7f6e\u9009\u9879\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Scikit-learn<\/strong><\/p>\n<\/p>\n<p><p>Scikit-learn\u662f\u4e00\u4e2a\u7528\u4e8e<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u7684\u5305\u3002\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u673a\u5668\u5b66\u4e60\u7b97\u6cd5\u548c\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u4e8e\u5206\u7c7b\u3001\u56de\u5f52\u3001\u805a\u7c7b\u7b49\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sklearn.linear_model import LinearRegression<\/p>\n<p>import numpy as np<\/p>\n<p>X = np.array([[1, 1], [1, 2], [2, 2], [2, 3]])<\/p>\n<p>y = np.dot(X, np.array([1, 2])) + 3<\/p>\n<p>reg = LinearRegression().fit(X, y)<\/p>\n<p>print(reg.coef_)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>Scikit-learn\u7684\u63a5\u53e3\u8bbe\u8ba1\u7b80\u6d01\uff0c\u6613\u4e8e\u4e0a\u624b\uff0c\u662f\u673a\u5668\u5b66\u4e60\u7684\u5165\u95e8\u5de5\u5177\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u5bf9Python\u5404\u79cd\u5305\u7684\u4f7f\u7528\u65b9\u6cd5\u7684\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u6211\u4eec\u53ef\u4ee5\u66f4\u597d\u5730\u5229\u7528\u8fd9\u4e9b\u5305\u6765\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3001\u7b80\u5316\u4ee3\u7801\u7f16\u5199\u3001\u589e\u52a0\u7a0b\u5e8f\u7684\u529f\u80fd\u6027\u3002\u5728\u9879\u76ee\u5f00\u53d1\u4e2d\uff0c\u9009\u62e9\u5408\u9002\u7684\u5305\uff0c\u5e76\u5408\u7406\u5730\u7ba1\u7406\u5305\u7684\u4f9d\u8d56\u5173\u7cfb\uff0c\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u9879\u76ee\u7684\u8d28\u91cf\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u9009\u62e9\u9002\u5408\u6211\u9879\u76ee\u7684Python\u5305\uff1f<\/strong><br \/>\u5728\u9009\u62e9Python\u5305\u65f6\uff0c\u9996\u5148\u9700\u8981\u660e\u786e\u9879\u76ee\u7684\u9700\u6c42\u3002\u53ef\u4ee5\u901a\u8fc7\u67e5\u9605\u76f8\u5173\u7684\u6587\u6863\u3001\u793e\u533a\u8bc4\u4ef7\u548c\u4f7f\u7528\u6848\u4f8b\u6765\u5224\u65ad\u4e00\u4e2a\u5305\u7684\u9002\u7528\u6027\u3002\u6b64\u5916\uff0c\u8003\u8651\u5305\u7684\u7ef4\u62a4\u9891\u7387\u3001\u66f4\u65b0\u5386\u53f2\u548c\u793e\u533a\u652f\u6301\u4e5f\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u4f7f\u7528\u6d41\u884c\u7684\u5305\u901a\u5e38\u80fd\u591f\u66f4\u5bb9\u6613\u627e\u5230\u6559\u7a0b\u548c\u89e3\u51b3\u65b9\u6848\u3002<\/p>\n<p><strong>Python\u5305\u7684\u5b89\u88c5\u65b9\u5f0f\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>Python\u5305\u7684\u5b89\u88c5\u4e3b\u8981\u901a\u8fc7\u5305\u7ba1\u7406\u5de5\u5177\u6765\u5b8c\u6210\u3002\u6700\u5e38\u7528\u7684\u662fpip\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4<code>pip install package_name<\/code>\u6765\u5b89\u88c5\u6240\u9700\u7684\u5305\u3002\u6b64\u5916\uff0cconda\u4e5f\u662f\u4e00\u4e2a\u6d41\u884c\u7684\u9009\u62e9\uff0c\u5c24\u5176\u662f\u5728\u6570\u636e\u79d1\u5b66\u9886\u57df\u3002\u4f7f\u7528<code>conda install package_name<\/code>\u547d\u4ee4\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b89\u88c5\u5305\u53ca\u5176\u4f9d\u8d56\u3002<\/p>\n<p><strong>\u5982\u4f55\u67e5\u627e\u548c\u7ba1\u7406\u5df2\u5b89\u88c5\u7684Python\u5305\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528<code>pip list<\/code>\u547d\u4ee4\u6765\u67e5\u770b\u5f53\u524d\u73af\u5883\u4e2d\u5df2\u5b89\u88c5\u7684\u6240\u6709\u5305\u53ca\u5176\u7248\u672c\u3002\u5982\u679c\u9700\u8981\u66f4\u65b0\u67d0\u4e2a\u5305\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip install --upgrade package_name<\/code>\u547d\u4ee4\u3002\u5bf9\u4e8e\u73af\u5883\u7ba1\u7406\uff0c\u53ef\u4ee5\u4f7f\u7528virtualenv\u6216conda\u73af\u5883\u6765\u9694\u79bb\u4e0d\u540c\u9879\u76ee\u7684\u4f9d\u8d56\uff0c\u786e\u4fdd\u9879\u76ee\u4e4b\u95f4\u4e0d\u4f1a\u4ea7\u751f\u51b2\u7a81\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c\u4f7f\u7528\u5404\u79cd\u5305\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3001\u7b80\u5316\u4ee3\u7801\u7f16\u5199\u3001\u589e\u52a0\u7a0b\u5e8f\u7684\u529f\u80fd\u6027\u3002Python\u5305\u7684\u4f7f\u7528\u4e3b\u8981\u5305\u62ec [&hellip;]","protected":false},"author":3,"featured_media":983328,"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\/983322"}],"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=983322"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/983322\/revisions"}],"predecessor-version":[{"id":983331,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/983322\/revisions\/983331"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/983328"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=983322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=983322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=983322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}