{"id":981685,"date":"2024-12-27T07:04:43","date_gmt":"2024-12-26T23:04:43","guid":{"rendered":""},"modified":"2024-12-27T07:04:47","modified_gmt":"2024-12-26T23:04:47","slug":"python%e5%a6%82%e4%bd%95%e5%af%b9%e6%8e%a5%e6%9c%9f%e8%b4%a7%e8%bd%af%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/981685.html","title":{"rendered":"python\u5982\u4f55\u5bf9\u63a5\u671f\u8d27\u8f6f\u4ef6"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24210518\/0e533b42-af57-455d-8a5b-610d8c881eec.webp\" alt=\"python\u5982\u4f55\u5bf9\u63a5\u671f\u8d27\u8f6f\u4ef6\" \/><\/p>\n<p><p> <strong>Python\u5bf9\u63a5\u671f\u8d27\u8f6f\u4ef6\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528API\u63a5\u53e3\u3001\u901a\u8fc7\u7b2c\u4e09\u65b9\u5e93\u3001\u81ea\u52a8\u5316\u4ea4\u6613\u5e73\u53f0\u3001\u6570\u636e\u89e3\u6790\u4e0e\u5904\u7406\u3002<\/strong> \u4f7f\u7528API\u63a5\u53e3\u662f\u5bf9\u63a5\u671f\u8d27\u8f6f\u4ef6\u7684\u5e38\u89c1\u65b9\u6cd5\uff0c\u8bb8\u591a\u671f\u8d27\u4ea4\u6613\u5e73\u53f0\u63d0\u4f9b\u516c\u5f00\u7684API\u63a5\u53e3\uff0c\u5141\u8bb8\u7528\u6237\u901a\u8fc7\u7f16\u7a0b\u65b9\u5f0f\u8fdb\u884c\u6570\u636e\u83b7\u53d6\u548c\u4ea4\u6613\u64cd\u4f5c\u3002\u8fd9\u79cd\u65b9\u6cd5\u7684\u4f18\u70b9\u662f\u7075\u6d3b\u6027\u9ad8\uff0c\u9002\u7528\u4e8e\u5404\u79cd\u81ea\u5b9a\u4e49\u9700\u6c42\u3002\u53ef\u4ee5\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528API\u63a5\u53e3\u5bf9\u63a5\u671f\u8d27\u8f6f\u4ef6\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528API\u63a5\u53e3<\/p>\n<\/p>\n<p><p>\u4f7f\u7528API\u63a5\u53e3\u662f\u5bf9\u63a5\u671f\u8d27\u8f6f\u4ef6\u7684\u5e38\u89c1\u65b9\u6cd5\u3002\u8bb8\u591a\u671f\u8d27\u4ea4\u6613\u5e73\u53f0\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684API\u63a5\u53e3\uff0c\u5141\u8bb8\u7528\u6237\u901a\u8fc7\u7f16\u7a0b\u65b9\u5f0f\u8fdb\u884c\u6570\u636e\u83b7\u53d6\u548c\u4ea4\u6613\u64cd\u4f5c\u3002API\u63a5\u53e3\u901a\u5e38\u63d0\u4f9b\u4e86\u884c\u60c5\u6570\u636e\u3001\u4ea4\u6613\u529f\u80fd\u548c\u8d26\u6237\u7ba1\u7406\u7b49\u591a\u79cd\u529f\u80fd\uff0c\u7528\u6237\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8fdb\u884c\u8c03\u7528\u3002<\/p>\n<\/p>\n<p><p>1.1 \u9009\u62e9\u5408\u9002\u7684API\u63a5\u53e3<\/p>\n<\/p>\n<p><p>\u5728\u4f7f\u7528API\u63a5\u53e3\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u9009\u62e9\u4e00\u4e2a\u5408\u9002\u7684\u671f\u8d27\u4ea4\u6613\u5e73\u53f0\u53ca\u5176\u63d0\u4f9b\u7684API\u63a5\u53e3\u3002\u9009\u62e9\u7684\u6807\u51c6\u5305\u62ec\u5e73\u53f0\u7684\u7a33\u5b9a\u6027\u3001API\u63a5\u53e3\u7684\u529f\u80fd\u4e30\u5bcc\u6027\u3001\u4f7f\u7528\u95e8\u69db\u548c\u8d39\u7528\u7b49\u3002\u5e38\u89c1\u7684\u671f\u8d27\u4ea4\u6613\u5e73\u53f0\u5305\u62ecInteractive Brokers\u3001CQG\u3001CTP\u7b49\u3002<\/p>\n<\/p>\n<p><p>1.2 \u83b7\u53d6API\u6587\u6863\u548c\u8ba4\u8bc1\u4fe1\u606f<\/p>\n<\/p>\n<p><p>\u9009\u62e9\u597d\u5e73\u53f0\u540e\uff0c\u901a\u5e38\u9700\u8981\u6ce8\u518c\u4e00\u4e2a\u5f00\u53d1\u8005\u8d26\u53f7\u5e76\u83b7\u53d6API\u6587\u6863\u3002API\u6587\u6863\u8be6\u7ec6\u8bf4\u660e\u4e86\u63a5\u53e3\u7684\u8c03\u7528\u65b9\u6cd5\u3001\u53c2\u6570\u8981\u6c42\u548c\u8fd4\u56de\u503c\u683c\u5f0f\u3002\u8ba4\u8bc1\u4fe1\u606f\u901a\u5e38\u5305\u62ecAPI Key\u548cSecret Key\uff0c\u7528\u4e8e\u9a8c\u8bc1\u7528\u6237\u8eab\u4efd\u548c\u6743\u9650\u3002<\/p>\n<\/p>\n<p><p>1.3 \u7f16\u5199Python\u4ee3\u7801<\/p>\n<\/p>\n<p><p>\u83b7\u53d6\u6587\u6863\u548c\u8ba4\u8bc1\u4fe1\u606f\u540e\uff0c\u5c31\u53ef\u4ee5\u5f00\u59cb\u7f16\u5199Python\u4ee3\u7801\u8fdb\u884c\u5bf9\u63a5\u3002\u901a\u5e38\u9700\u8981\u4f7f\u7528requests\u5e93\u6216\u7c7b\u4f3c\u7684HTTP\u5e93\u53d1\u9001HTTP\u8bf7\u6c42\u5230API\u670d\u52a1\u5668\uff0c\u83b7\u53d6\u6570\u636e\u6216\u6267\u884c\u4ea4\u6613\u64cd\u4f5c\u3002\u4ee5\u83b7\u53d6\u884c\u60c5\u6570\u636e\u4e3a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>api_key = &#39;your_api_key&#39;<\/p>\n<p>url = &#39;https:\/\/api.broker.com\/v1\/marketdata&#39;<\/p>\n<p>headers = {<\/p>\n<p>    &#39;Authorization&#39;: f&#39;Bearer {api_key}&#39;<\/p>\n<p>}<\/p>\n<p>params = {<\/p>\n<p>    &#39;symbol&#39;: &#39;AAPL&#39;,<\/p>\n<p>    &#39;interval&#39;: &#39;1m&#39;<\/p>\n<p>}<\/p>\n<p>response = requests.get(url, headers=headers, params=params)<\/p>\n<p>data = response.json()<\/p>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>1.4 \u5904\u7406API\u8fd4\u56de\u7684\u6570\u636e<\/p>\n<\/p>\n<p><p>API\u63a5\u53e3\u901a\u5e38\u8fd4\u56deJSON\u683c\u5f0f\u7684\u6570\u636e\uff0cPython\u4e2d\u53ef\u4ee5\u4f7f\u7528json\u5e93\u5c06\u5176\u89e3\u6790\u4e3a\u5b57\u5178\u6216\u5217\u8868\uff0c\u7136\u540e\u8fdb\u884c\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u3002\u5904\u7406\u6570\u636e\u65f6\u9700\u8981\u6ce8\u610f\u63a5\u53e3\u6587\u6863\u4e2d\u63cf\u8ff0\u7684\u6570\u636e\u7ed3\u6784\u548c\u5b57\u6bb5\u542b\u4e49\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u901a\u8fc7\u7b2c\u4e09\u65b9\u5e93<\/p>\n<\/p>\n<p><p>\u9664\u4e86\u76f4\u63a5\u4f7f\u7528API\u63a5\u53e3\u5916\uff0c\u8fd8\u6709\u8bb8\u591a\u7b2c\u4e09\u65b9\u5e93\u5c01\u88c5\u4e86\u5bf9\u5e38\u89c1\u671f\u8d27\u4ea4\u6613\u5e73\u53f0\u7684API\u8c03\u7528\uff0c\u63d0\u4f9b\u4e86\u66f4\u9ad8\u5c42\u6b21\u7684\u62bd\u8c61\u548c\u66f4\u7b80\u5355\u7684\u4f7f\u7528\u65b9\u6cd5\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><p>2.1 \u4f7f\u7528ib_insync\u5e93<\/p>\n<\/p>\n<p><p>ib_insync\u662f\u4e00\u4e2a\u7528\u4e8eInteractive Brokers API\u7684Python\u5e93\uff0c\u63d0\u4f9b\u4e86\u7b80\u5355\u6613\u7528\u7684\u5f02\u6b65\u63a5\u53e3\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u884c\u60c5\u6570\u636e\u83b7\u53d6\u548c\u4ea4\u6613\u64cd\u4f5c\u3002\u5b89\u88c5\u548c\u4f7f\u7528\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install ib_insync<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><pre><code class=\"language-python\">from ib_insync import *<\/p>\n<p>ib = IB()<\/p>\n<p>ib.connect(&#39;127.0.0.1&#39;, 7496, clientId=1)<\/p>\n<p>contract = Stock(&#39;AAPL&#39;, &#39;SMART&#39;, &#39;USD&#39;)<\/p>\n<p>bars = ib.reqHistoricalData(contract, endDateTime=&#39;&#39;, durationStr=&#39;1 D&#39;,<\/p>\n<p>                            barSizeSetting=&#39;1 min&#39;, whatToShow=&#39;MIDPOINT&#39;, useRTH=True)<\/p>\n<p>for bar in bars:<\/p>\n<p>    print(bar)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>2.2 \u4f7f\u7528ccxt\u5e93<\/p>\n<\/p>\n<p><p>ccxt\u662f\u4e00\u4e2a\u652f\u6301\u591a\u5bb6\u4ea4\u6613\u6240\u7684\u52a0\u5bc6\u8d27\u5e01\u4ea4\u6613\u5e93\uff0c\u4f46\u4e5f\u652f\u6301\u90e8\u5206\u671f\u8d27\u4ea4\u6613\u5e73\u53f0\u3002\u901a\u8fc7ccxt\u5e93\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u884c\u60c5\u6570\u636e\u83b7\u53d6\u3001\u4e0b\u5355\u548c\u8d26\u6237\u7ba1\u7406\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install ccxt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><pre><code class=\"language-python\">import ccxt<\/p>\n<p>exchange = ccxt.binance({<\/p>\n<p>    &#39;apiKey&#39;: &#39;your_api_key&#39;,<\/p>\n<p>    &#39;secret&#39;: &#39;your_secret_key&#39;,<\/p>\n<p>})<\/p>\n<p>markets = exchange.load_markets()<\/p>\n<p>ticker = exchange.fetch_ticker(&#39;BTC\/USDT&#39;)<\/p>\n<p>print(ticker)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u81ea\u52a8\u5316\u4ea4\u6613\u5e73\u53f0<\/p>\n<\/p>\n<p><p>\u6709\u4e9b\u81ea\u52a8\u5316\u4ea4\u6613\u5e73\u53f0\u63d0\u4f9b\u4e86\u5bf9Python\u7684\u652f\u6301\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u5e73\u53f0\u4e0a\u7f16\u5199Python\u7b56\u7565\u4ee3\u7801\uff0c\u5e73\u53f0\u8d1f\u8d23\u4e0e\u671f\u8d27\u4ea4\u6613\u6240\u7684\u5bf9\u63a5\u3002\u5e38\u89c1\u7684\u5e73\u53f0\u5305\u62ecQuantConnect\u3001Quantlib\u3001Zipline\u7b49\u3002<\/p>\n<\/p>\n<p><p>3.1 \u4f7f\u7528QuantConnect<\/p>\n<\/p>\n<p><p>QuantConnect\u662f\u4e00\u4e2a\u57fa\u4e8e\u4e91\u7684\u7b97\u6cd5\u4ea4\u6613\u5e73\u53f0\uff0c\u652f\u6301\u591a\u79cd\u8bed\u8a00\u548c\u4ea4\u6613\u6240\u3002\u7528\u6237\u53ef\u4ee5\u5728\u5e73\u53f0\u4e0a\u7f16\u5199Python\u7b56\u7565\uff0c\u8fdb\u884c\u56de\u6d4b\u548c\u5b9e\u76d8\u4ea4\u6613\u3002\u4f7f\u7528\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u6ce8\u518cQuantConnect\u8d26\u53f7\u5e76\u767b\u5f55<\/li>\n<li>\u521b\u5efa\u65b0\u7684Python\u9879\u76ee<\/li>\n<li>\u5728\u9879\u76ee\u4e2d\u7f16\u5199\u7b56\u7565\u4ee3\u7801\uff0c\u6307\u5b9a\u4ea4\u6613\u6240\u548c\u6807\u7684<\/li>\n<li>\u8fdb\u884c\u56de\u6d4b\u548c\u53c2\u6570\u4f18\u5316<\/li>\n<li>\u90e8\u7f72\u7b56\u7565\u5230\u5b9e\u76d8\u4ea4\u6613<\/li>\n<\/ul>\n<p><p>3.2 \u4f7f\u7528Zipline<\/p>\n<\/p>\n<p><p>Zipline\u662f\u4e00\u4e2aPython\u7684\u56de\u6d4b\u6846\u67b6\uff0c\u867d\u7136\u4e0d\u76f4\u63a5\u652f\u6301\u5b9e\u76d8\u4ea4\u6613\uff0c\u4f46\u53ef\u4ee5\u7528\u6765\u5f00\u53d1\u548c\u6d4b\u8bd5\u671f\u8d27\u4ea4\u6613\u7b56\u7565\u3002\u4f7f\u7528\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install zipline<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><pre><code class=\"language-python\">import zipline<\/p>\n<p>from zipline.api import order, record, symbol<\/p>\n<p>def initialize(context):<\/p>\n<p>    context.asset = symbol(&#39;AAPL&#39;)<\/p>\n<p>def handle_data(context, data):<\/p>\n<p>    order(context.asset, 10)<\/p>\n<p>    record(AAPL=data.current(context.asset, &#39;price&#39;))<\/p>\n<p>perf = zipline.run_algorithm(start=pd.Timestamp(&#39;2020-01-01&#39;, tz=&#39;utc&#39;),<\/p>\n<p>                             end=pd.Timestamp(&#39;2021-01-01&#39;, tz=&#39;utc&#39;),<\/p>\n<p>                             initialize=initialize,<\/p>\n<p>                             handle_data=handle_data,<\/p>\n<p>                             capital_base=10000)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u6570\u636e\u89e3\u6790\u4e0e\u5904\u7406<\/p>\n<\/p>\n<p><p>\u5728\u5bf9\u63a5\u671f\u8d27\u8f6f\u4ef6\u65f6\uff0c\u6570\u636e\u7684\u89e3\u6790\u4e0e\u5904\u7406\u662f\u4e00\u4e2a\u91cd\u8981\u73af\u8282\u3002Python\u62e5\u6709\u4e30\u5bcc\u7684\u6570\u636e\u5904\u7406\u5e93\uff0c\u53ef\u4ee5\u7528\u4e8e\u89e3\u6790\u3001\u6e05\u6d17\u3001\u5206\u6790\u548c\u53ef\u89c6\u5316\u6570\u636e\u3002<\/p>\n<\/p>\n<p><p>4.1 \u4f7f\u7528Pandas\u8fdb\u884c\u6570\u636e\u5904\u7406<\/p>\n<\/p>\n<p><p>Pandas\u662fPython\u4e2d\u6700\u5e38\u7528\u7684\u6570\u636e\u5206\u6790\u5e93\uff0c\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u7ed3\u6784\u548c\u5904\u7406\u5de5\u5177\u3002\u53ef\u4ee5\u7528\u6765\u5904\u7406\u4eceAPI\u63a5\u53e3\u83b7\u53d6\u7684\u884c\u60c5\u6570\u636e\uff0c\u5305\u62ec\u6570\u636e\u6e05\u6d17\u3001\u8f6c\u6362\u3001\u5408\u5e76\u548c\u7edf\u8ba1\u5206\u6790\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>data = {<\/p>\n<p>    &#39;time&#39;: [&#39;2023-01-01 10:00&#39;, &#39;2023-01-01 10:01&#39;],<\/p>\n<p>    &#39;price&#39;: [100, 101]<\/p>\n<p>}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<p>df[&#39;time&#39;] = pd.to_datetime(df[&#39;time&#39;])<\/p>\n<p>df.set_index(&#39;time&#39;, inplace=True)<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>4.2 \u4f7f\u7528Matplotlib\u8fdb\u884c\u6570\u636e\u53ef\u89c6\u5316<\/p>\n<\/p>\n<p><p>Matplotlib\u662fPython\u7684\u7ed8\u56fe\u5e93\uff0c\u53ef\u4ee5\u7528\u6765\u7ed8\u5236\u5404\u79cd\u56fe\u8868\uff0c\u5e2e\u52a9\u7528\u6237\u76f4\u89c2\u5730\u5206\u6790\u548c\u5c55\u793a\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>plt.plot(df.index, df[&#39;price&#39;])<\/p>\n<p>plt.title(&#39;Price Over Time&#39;)<\/p>\n<p>plt.xlabel(&#39;Time&#39;)<\/p>\n<p>plt.ylabel(&#39;Price&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e94\u3001\u6ce8\u610f\u4e8b\u9879<\/p>\n<\/p>\n<p><p>\u5728\u4f7f\u7528Python\u5bf9\u63a5\u671f\u8d27\u8f6f\u4ef6\u65f6\uff0c\u9700\u8981\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<\/p>\n<p><p>5.1 \u4e86\u89e3\u671f\u8d27\u5e02\u573a\u7684\u98ce\u9669<\/p>\n<\/p>\n<p><p>\u671f\u8d27\u4ea4\u6613\u6d89\u53ca\u9ad8\u98ce\u9669\uff0c\u5e02\u573a\u6ce2\u52a8\u53ef\u80fd\u5bfc\u81f4\u635f\u5931\u3002\u5728\u5f00\u53d1\u4ea4\u6613\u7b56\u7565\u65f6\uff0c\u9700\u8981\u8fdb\u884c\u5145\u5206\u7684\u56de\u6d4b\u548c\u98ce\u9669\u63a7\u5236\u3002<\/p>\n<\/p>\n<p><p>5.2 \u786e\u4fdd\u4ee3\u7801\u7684\u53ef\u9760\u6027<\/p>\n<\/p>\n<p><p>\u5728\u5b9e\u76d8\u4ea4\u6613\u4e2d\uff0c\u4ee3\u7801\u7684\u53ef\u9760\u6027\u548c\u7a33\u5b9a\u6027\u81f3\u5173\u91cd\u8981\u3002\u9700\u8981\u8fdb\u884c\u5145\u5206\u7684\u6d4b\u8bd5\uff0c\u786e\u4fdd\u4ee3\u7801\u80fd\u591f\u6b63\u786e\u5904\u7406\u5404\u79cd\u5f02\u5e38\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><p>5.3 \u5408\u6cd5\u5408\u89c4<\/p>\n<\/p>\n<p><p>\u5728\u4f7f\u7528API\u63a5\u53e3\u8fdb\u884c\u81ea\u52a8\u5316\u4ea4\u6613\u65f6\uff0c\u9700\u8981\u9075\u5b88\u76f8\u5173\u6cd5\u5f8b\u6cd5\u89c4\u548c\u4ea4\u6613\u6240\u7684\u89c4\u5b9a\uff0c\u786e\u4fdd\u5408\u6cd5\u5408\u89c4\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0cPython\u53ef\u4ee5\u6709\u6548\u5730\u5bf9\u63a5\u671f\u8d27\u8f6f\u4ef6\uff0c\u5b9e\u73b0\u6570\u636e\u83b7\u53d6\u3001\u81ea\u52a8\u5316\u4ea4\u6613\u548c\u7b56\u7565\u5206\u6790\u3002\u5e0c\u671b\u4ee5\u4e0a\u5185\u5bb9\u5bf9\u60a8\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u4e0e\u671f\u8d27\u4ea4\u6613\u8f6f\u4ef6\u8fdb\u884c\u6570\u636e\u4ea4\u4e92\uff1f<\/strong><br \/>\u4f7f\u7528Python\u4e0e\u671f\u8d27\u4ea4\u6613\u8f6f\u4ef6\u8fdb\u884c\u6570\u636e\u4ea4\u4e92\u901a\u5e38\u6d89\u53ca\u5230API\uff08\u5e94\u7528\u7a0b\u5e8f\u7f16\u7a0b\u63a5\u53e3\uff09\u7684\u4f7f\u7528\u3002\u8bb8\u591a\u671f\u8d27\u8f6f\u4ef6\u63d0\u4f9bAPI\u6587\u6863\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u901a\u8fc7\u8fd9\u4e9b\u6587\u6863\u4e86\u89e3\u5982\u4f55\u53d1\u9001\u8bf7\u6c42\u3001\u83b7\u53d6\u5e02\u573a\u6570\u636e\u4ee5\u53ca\u6267\u884c\u4ea4\u6613\u3002\u5177\u4f53\u6b65\u9aa4\u5305\u62ec\uff1a\u6ce8\u518c\u83b7\u53d6API\u5bc6\u94a5\u3001\u5b89\u88c5\u76f8\u5173\u5e93\uff08\u5982requests\u3001pandas\u7b49\uff09\uff0c\u7136\u540e\u7f16\u5199\u4ee3\u7801\u6765\u8fde\u63a5API\uff0c\u83b7\u53d6\u5b9e\u65f6\u6570\u636e\u6216\u6267\u884c\u4ea4\u6613\u6307\u4ee4\u3002<\/p>\n<p><strong>Python\u53ef\u4ee5\u5b9e\u73b0\u54ea\u4e9b\u671f\u8d27\u4ea4\u6613\u7b56\u7565\uff1f<\/strong><br \/>Python\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u53ef\u4ee5\u5b9e\u73b0\u591a\u79cd\u671f\u8d27\u4ea4\u6613\u7b56\u7565\u3002\u5e38\u89c1\u7684\u7b56\u7565\u5305\u62ec\u8d8b\u52bf\u8ddf\u8e2a\u3001\u5957\u5229\u3001\u5e02\u573a\u4e2d\u6027\u7b56\u7565\u7b49\u3002\u4f7f\u7528Python\uff0c\u60a8\u53ef\u4ee5\u5229\u7528\u5386\u53f2\u6570\u636e\u8fdb\u884c\u56de\u6d4b\uff0c\u4f18\u5316\u53c2\u6570\uff0c\u8bc4\u4f30\u7b56\u7565\u8868\u73b0\u3002\u6b64\u5916\uff0c\u901a\u8fc7<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u5e93\uff08\u5982scikit-learn\u3001TensorFlow\u7b49\uff09\uff0c\u60a8\u8fd8\u53ef\u4ee5\u5f00\u53d1\u66f4\u590d\u6742\u7684\u9884\u6d4b\u6a21\u578b\uff0c\u5e2e\u52a9\u51b3\u7b56\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u5904\u7406\u671f\u8d27\u5e02\u573a\u7684\u5b9e\u65f6\u6570\u636e\uff1f<\/strong><br \/>\u5904\u7406\u671f\u8d27\u5e02\u573a\u7684\u5b9e\u65f6\u6570\u636e\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u5b9e\u73b0\u3002\u8bb8\u591a\u4ea4\u6613\u8f6f\u4ef6\u63d0\u4f9bWebSocket\u6216REST API\u6765\u83b7\u53d6\u5b9e\u65f6\u6570\u636e\u6d41\u3002\u4f7f\u7528Python\u7684asyncio\u5e93\u53ef\u4ee5\u6709\u6548\u7ba1\u7406\u5f02\u6b65\u8bf7\u6c42\uff0c\u786e\u4fdd\u5feb\u901f\u5904\u7406\u6570\u636e\u3002\u6b64\u5916\uff0c\u7ed3\u5408pandas\u5e93\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5bf9\u6570\u636e\u8fdb\u884c\u6e05\u6d17\u3001\u5206\u6790\u548c\u53ef\u89c6\u5316\uff0c\u4ece\u800c\u5e2e\u52a9\u8fdb\u884c\u5b9e\u65f6\u76d1\u63a7\u548c\u51b3\u7b56\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u5bf9\u63a5\u671f\u8d27\u8f6f\u4ef6\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528API\u63a5\u53e3\u3001\u901a\u8fc7\u7b2c\u4e09\u65b9\u5e93\u3001\u81ea\u52a8\u5316\u4ea4\u6613\u5e73\u53f0\u3001\u6570\u636e\u89e3\u6790\u4e0e\u5904\u7406\u3002 \u4f7f\u7528API [&hellip;]","protected":false},"author":3,"featured_media":981700,"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\/981685"}],"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=981685"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/981685\/revisions"}],"predecessor-version":[{"id":981704,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/981685\/revisions\/981704"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/981700"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=981685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=981685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=981685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}