{"id":1038995,"date":"2024-12-31T12:28:49","date_gmt":"2024-12-31T04:28:49","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1038995.html"},"modified":"2024-12-31T12:28:52","modified_gmt":"2024-12-31T04:28:52","slug":"python-%e5%a6%82%e4%bd%95%e6%b7%bb%e5%8a%a0%e4%b8%80%e8%a1%8c%e6%95%b0%e6%8d%ae","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1038995.html","title":{"rendered":"python \u5982\u4f55\u6dfb\u52a0\u4e00\u884c\u6570\u636e"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/01f2fd80-00db-4d5e-be57-541b019df81c.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"python \u5982\u4f55\u6dfb\u52a0\u4e00\u884c\u6570\u636e\" \/><\/p>\n<p><p> <strong>Python\u4e2d\u6dfb\u52a0\u4e00\u884c\u6570\u636e\u7684\u65b9\u5f0f\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528\u5217\u8868\u3001\u5b57\u5178\u3001Pandas\u5e93\u7b49\u3002\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u4f7f\u7528Pandas\u5e93\uff0c\u5b83\u53ef\u4ee5\u65b9\u4fbf\u5730\u64cd\u4f5c\u548c\u7ba1\u7406\u6570\u636e\u3002\u8be6\u7ec6\u63cf\u8ff0\uff1aPandas\u5e93\u652f\u6301DataFrame\u7ed3\u6784\uff0c\u63d0\u4f9b\u4e86<code>append<\/code>\u548c<code>loc<\/code>\u65b9\u6cd5\u6765\u6dfb\u52a0\u6570\u636e\u3002<\/strong><\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u4f7f\u7528\u5217\u8868\u6dfb\u52a0\u4e00\u884c\u6570\u636e<\/h2>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u5217\u8868\u662f\u4e00\u79cd\u975e\u5e38\u5e38\u7528\u7684\u6570\u636e\u7ed3\u6784\u3002\u53ef\u4ee5\u4f7f\u7528<code>append<\/code>\u65b9\u6cd5\u5411\u5217\u8868\u4e2d\u6dfb\u52a0\u4e00\u884c\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = []<\/p>\n<p>data.append([&#39;John&#39;, 28, &#39;Engineer&#39;])<\/p>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u7a7a\u5217\u8868<code>data<\/code>\uff0c\u7136\u540e\u4f7f\u7528<code>append<\/code>\u65b9\u6cd5\u5411\u5176\u4e2d\u6dfb\u52a0\u4e86\u4e00\u884c\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h2>\u4e8c\u3001\u4f7f\u7528\u5b57\u5178\u6dfb\u52a0\u4e00\u884c\u6570\u636e<\/h2>\n<\/p>\n<p><p>\u5b57\u5178\u5728Python\u4e2d\u4e5f\u662f\u975e\u5e38\u5e38\u7528\u7684\u6570\u636e\u7ed3\u6784\u3002\u53ef\u4ee5\u4f7f\u7528\u952e\u503c\u5bf9\u7684\u5f62\u5f0f\u5411\u5b57\u5178\u4e2d\u6dfb\u52a0\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = {}<\/p>\n<p>data[&#39;John&#39;] = {&#39;Age&#39;: 28, &#39;Job&#39;: &#39;Engineer&#39;}<\/p>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u7a7a\u5b57\u5178<code>data<\/code>\uff0c\u7136\u540e\u4f7f\u7528\u952e\u503c\u5bf9\u7684\u5f62\u5f0f\u5411\u5176\u4e2d\u6dfb\u52a0\u4e86\u4e00\u884c\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u4f7f\u7528Pandas\u5e93\u6dfb\u52a0\u4e00\u884c\u6570\u636e<\/h2>\n<\/p>\n<p><p>Pandas\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u5e93\uff0c\u7279\u522b\u9002\u5408\u5904\u7406\u8868\u683c\u6570\u636e\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Pandas\u7684<code>DataFrame<\/code>\u7ed3\u6784\u6765\u6dfb\u52a0\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aDataFrame<\/strong><\/h2>\n<p>df = pd.DataFrame(columns=[&#39;Name&#39;, &#39;Age&#39;, &#39;Job&#39;])<\/p>\n<h2><strong>\u6dfb\u52a0\u4e00\u884c\u6570\u636e<\/strong><\/h2>\n<p>df = df.append({&#39;Name&#39;: &#39;John&#39;, &#39;Age&#39;: 28, &#39;Job&#39;: &#39;Engineer&#39;}, ignore_index=True)<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5bfc\u5165\u4e86Pandas\u5e93\uff0c\u7136\u540e\u521b\u5efa\u4e86\u4e00\u4e2a\u7a7a\u7684<code>DataFrame<\/code>\uff0c\u63a5\u7740\u4f7f\u7528<code>append<\/code>\u65b9\u6cd5\u6dfb\u52a0\u4e86\u4e00\u884c\u6570\u636e\u3002<code>ignore_index=True<\/code>\u53c2\u6570\u7684\u4f5c\u7528\u662f\u8ba9Pandas\u81ea\u52a8\u4e3a\u65b0\u884c\u5206\u914d\u7d22\u5f15\u3002<\/p>\n<\/p>\n<p><h2>\u8be6\u7ec6\u63cf\u8ff0\uff1a\u4f7f\u7528Pandas\u5e93\u6dfb\u52a0\u4e00\u884c\u6570\u636e<\/h2>\n<\/p>\n<p><p>Pandas\u5e93\u662f\u6570\u636e\u79d1\u5b66\u5bb6\u548c\u5206\u6790\u5e08\u975e\u5e38\u559c\u7231\u7684\u5de5\u5177\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u975e\u5e38\u7075\u6d3b\u548c\u9ad8\u6548\u7684\u6570\u636e\u64cd\u4f5c\u65b9\u6cd5\u3002\u5728Pandas\u4e2d\uff0c\u6570\u636e\u901a\u5e38\u5b58\u50a8\u5728<code>DataFrame<\/code>\u7ed3\u6784\u4e2d\u3002<code>DataFrame<\/code>\u53ef\u4ee5\u770b\u4f5c\u662f\u4e00\u4e2a\u8868\u683c\uff0c\u7c7b\u4f3c\u4e8eExcel\u8868\u683c\u6216\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u8868\u3002<\/p>\n<\/p>\n<p><p>\u5728Pandas\u4e2d\u6dfb\u52a0\u4e00\u884c\u6570\u636e\u6709\u591a\u79cd\u65b9\u6cd5\uff0c\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u51e0\u79cd\u5e38\u7528\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<ol>\n<li>\u4f7f\u7528<code>append<\/code>\u65b9\u6cd5<\/li>\n<\/ol>\n<hr>\n<p><p><code>append<\/code>\u65b9\u6cd5\u662f\u6700\u7b80\u5355\u548c\u76f4\u63a5\u7684\u65b9\u6cd5\u4e4b\u4e00\u3002\u5b83\u53ef\u4ee5\u5c06\u4e00\u4e2a\u5b57\u5178\u6216\u53e6\u4e00\u4e2a<code>DataFrame<\/code>\u7684\u5185\u5bb9\u6dfb\u52a0\u5230\u73b0\u6709\u7684<code>DataFrame<\/code>\u4e2d\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aDataFrame<\/strong><\/h2>\n<p>df = pd.DataFrame(columns=[&#39;Name&#39;, &#39;Age&#39;, &#39;Job&#39;])<\/p>\n<h2><strong>\u6dfb\u52a0\u4e00\u884c\u6570\u636e<\/strong><\/h2>\n<p>df = df.append({&#39;Name&#39;: &#39;John&#39;, &#39;Age&#39;: 28, &#39;Job&#39;: &#39;Engineer&#39;}, ignore_index=True)<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u521b\u5efa\u4e86\u4e00\u4e2a\u7a7a\u7684<code>DataFrame<\/code>\uff0c\u7136\u540e\u4f7f\u7528<code>append<\/code>\u65b9\u6cd5\u5c06\u4e00\u4e2a\u5b57\u5178\u5f62\u5f0f\u7684\u6570\u636e\u6dfb\u52a0\u5230<code>DataFrame<\/code>\u4e2d\u3002<code>ignore_index=True<\/code>\u53c2\u6570\u7684\u4f5c\u7528\u662f\u8ba9Pandas\u81ea\u52a8\u4e3a\u65b0\u884c\u5206\u914d\u7d22\u5f15\u3002<\/p>\n<\/p>\n<p><p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c<code>append<\/code>\u65b9\u6cd5\u6bcf\u6b21\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684<code>DataFrame<\/code>\uff0c\u56e0\u6b64\u5728\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u65f6\uff0c\u9891\u7e41\u4f7f\u7528<code>append<\/code>\u65b9\u6cd5\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6027\u80fd\u95ee\u9898\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li>\u4f7f\u7528<code>loc<\/code>\u65b9\u6cd5<\/li>\n<\/ol>\n<hr>\n<p><p><code>loc<\/code>\u65b9\u6cd5\u662fPandas\u4e2d\u975e\u5e38\u5f3a\u5927\u7684\u4e00\u4e2a\u65b9\u6cd5\uff0c\u53ef\u4ee5\u901a\u8fc7\u6807\u7b7e\u8bbf\u95ee\u6570\u636e\u3002\u6211\u4eec\u4e5f\u53ef\u4ee5\u4f7f\u7528<code>loc<\/code>\u65b9\u6cd5\u5411<code>DataFrame<\/code>\u4e2d\u6dfb\u52a0\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aDataFrame<\/strong><\/h2>\n<p>df = pd.DataFrame(columns=[&#39;Name&#39;, &#39;Age&#39;, &#39;Job&#39;])<\/p>\n<h2><strong>\u6dfb\u52a0\u4e00\u884c\u6570\u636e<\/strong><\/h2>\n<p>df.loc[0] = [&#39;John&#39;, 28, &#39;Engineer&#39;]<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>loc<\/code>\u65b9\u6cd5\u76f4\u63a5\u5411<code>DataFrame<\/code>\u4e2d\u6dfb\u52a0\u4e86\u4e00\u884c\u6570\u636e\u3002\u4e0e<code>append<\/code>\u65b9\u6cd5\u4e0d\u540c\uff0c<code>loc<\/code>\u65b9\u6cd5\u4e0d\u4f1a\u521b\u5efa\u65b0\u7684<code>DataFrame<\/code>\uff0c\u56e0\u6b64\u5728\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u65f6\u6027\u80fd\u66f4\u597d\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li>\u4f7f\u7528<code>concat<\/code>\u65b9\u6cd5<\/li>\n<\/ol>\n<hr>\n<p><p><code>concat<\/code>\u65b9\u6cd5\u53ef\u4ee5\u5c06\u591a\u4e2a<code>DataFrame<\/code>\u62fc\u63a5\u5728\u4e00\u8d77\u3002\u6211\u4eec\u53ef\u4ee5\u5148\u521b\u5efa\u4e00\u4e2a\u65b0\u7684<code>DataFrame<\/code>\uff0c\u7136\u540e\u4f7f\u7528<code>concat<\/code>\u65b9\u6cd5\u5c06\u5176\u6dfb\u52a0\u5230\u73b0\u6709\u7684<code>DataFrame<\/code>\u4e2d\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aDataFrame<\/strong><\/h2>\n<p>df = pd.DataFrame(columns=[&#39;Name&#39;, &#39;Age&#39;, &#39;Job&#39;])<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684DataFrame<\/strong><\/h2>\n<p>new_data = pd.DataFrame([[&#39;John&#39;, 28, &#39;Engineer&#39;]], columns=[&#39;Name&#39;, &#39;Age&#39;, &#39;Job&#39;])<\/p>\n<h2><strong>\u4f7f\u7528concat\u65b9\u6cd5\u6dfb\u52a0\u6570\u636e<\/strong><\/h2>\n<p>df = pd.concat([df, new_data], ignore_index=True)<\/p>\n<p>print(df)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u521b\u5efa\u4e86\u4e00\u4e2a\u7a7a\u7684<code>DataFrame<\/code>\uff0c\u7136\u540e\u521b\u5efa\u4e86\u4e00\u4e2a\u5305\u542b\u65b0\u6570\u636e\u7684<code>DataFrame<\/code>\uff0c\u63a5\u7740\u4f7f\u7528<code>concat<\/code>\u65b9\u6cd5\u5c06\u65b0\u6570\u636e\u6dfb\u52a0\u5230\u73b0\u6709\u7684<code>DataFrame<\/code>\u4e2d\u3002<code>ignore_index=True<\/code>\u53c2\u6570\u7684\u4f5c\u7528\u662f\u8ba9Pandas\u81ea\u52a8\u4e3a\u65b0\u884c\u5206\u914d\u7d22\u5f15\u3002<\/p>\n<\/p>\n<p><h2>\u56db\u3001\u6bd4\u8f83\u4e0d\u540c\u65b9\u6cd5\u7684\u6027\u80fd<\/h2>\n<\/p>\n<p><p>\u5728\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\u65f6\uff0c\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u975e\u5e38\u91cd\u8981\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u6bd4\u8f83<code>append<\/code>\u3001<code>loc<\/code>\u548c<code>concat<\/code>\u65b9\u6cd5\u7684\u6027\u80fd\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>import time<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u7a7a\u7684DataFrame<\/strong><\/h2>\n<p>df = pd.DataFrame(columns=[&#39;Name&#39;, &#39;Age&#39;, &#39;Job&#39;])<\/p>\n<h2><strong>\u4f7f\u7528append\u65b9\u6cd5\u6dfb\u52a010000\u884c\u6570\u636e<\/strong><\/h2>\n<p>start_time = time.time()<\/p>\n<p>for i in range(10000):<\/p>\n<p>    df = df.append({&#39;Name&#39;: &#39;John&#39;, &#39;Age&#39;: 28, &#39;Job&#39;: &#39;Engineer&#39;}, ignore_index=True)<\/p>\n<p>print(&quot;Append method took %s seconds&quot; % (time.time() - start_time))<\/p>\n<h2><strong>\u4f7f\u7528loc\u65b9\u6cd5\u6dfb\u52a010000\u884c\u6570\u636e<\/strong><\/h2>\n<p>df = pd.DataFrame(columns=[&#39;Name&#39;, &#39;Age&#39;, &#39;Job&#39;])<\/p>\n<p>start_time = time.time()<\/p>\n<p>for i in range(10000):<\/p>\n<p>    df.loc[i] = [&#39;John&#39;, 28, &#39;Engineer&#39;]<\/p>\n<p>print(&quot;Loc method took %s seconds&quot; % (time.time() - start_time))<\/p>\n<h2><strong>\u4f7f\u7528concat\u65b9\u6cd5\u6dfb\u52a010000\u884c\u6570\u636e<\/strong><\/h2>\n<p>df = pd.DataFrame(columns=[&#39;Name&#39;, &#39;Age&#39;, &#39;Job&#39;])<\/p>\n<p>start_time = time.time()<\/p>\n<p>new_data = pd.DataFrame([[&#39;John&#39;, 28, &#39;Engineer&#39;]] * 10000, columns=[&#39;Name&#39;, &#39;Age&#39;, &#39;Job&#39;])<\/p>\n<p>df = pd.concat([df, new_data], ignore_index=True)<\/p>\n<p>print(&quot;Concat method took %s seconds&quot; % (time.time() - start_time))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5206\u522b\u4f7f\u7528<code>append<\/code>\u3001<code>loc<\/code>\u548c<code>concat<\/code>\u65b9\u6cd5\u5411<code>DataFrame<\/code>\u4e2d\u6dfb\u52a0\u4e8610000\u884c\u6570\u636e\uff0c\u5e76\u8bb0\u5f55\u4e86\u6bcf\u79cd\u65b9\u6cd5\u6240\u8017\u8d39\u7684\u65f6\u95f4\u3002\u5b9e\u9a8c\u7ed3\u679c\u8868\u660e\uff0c<code>loc<\/code>\u65b9\u6cd5\u548c<code>concat<\/code>\u65b9\u6cd5\u7684\u6027\u80fd\u660e\u663e\u4f18\u4e8e<code>append<\/code>\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h2>\u4e94\u3001\u603b\u7ed3<\/h2>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u6dfb\u52a0\u4e00\u884c\u6570\u636e\u6709\u591a\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528\u5217\u8868\u3001\u5b57\u5178\u548cPandas\u5e93\u3002\u5bf9\u4e8e\u5904\u7406\u5927\u89c4\u6a21\u6570\u636e\uff0c\u63a8\u8350\u4f7f\u7528Pandas\u5e93\uff0c\u5e76\u9009\u62e9\u6027\u80fd\u8f83\u4f18\u7684\u65b9\u6cd5\uff0c\u5982<code>loc<\/code>\u548c<code>concat<\/code>\u65b9\u6cd5\u3002\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u6570\u636e\u5904\u7406\u7684\u6548\u7387\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5c06\u6570\u636e\u6dfb\u52a0\u5230\u5217\u8868\u4e2d\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>append()<\/code>\u65b9\u6cd5\u5c06\u65b0\u6570\u636e\u6dfb\u52a0\u5230\u5217\u8868\u7684\u672b\u5c3e\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u6709\u4e00\u4e2a\u5217\u8868<code>data<\/code>\uff0c\u53ef\u4ee5\u901a\u8fc7<code>data.append(new_item)<\/code>\u5c06<code>new_item<\/code>\u6dfb\u52a0\u5230\u5217\u8868\u4e2d\u3002\u8fd9\u6837\uff0c\u60a8\u53ef\u4ee5\u52a8\u6001\u5730\u6269\u5c55\u5217\u8868\u5185\u5bb9\u3002<\/p>\n<p><strong>Python\u4e2d\u5982\u4f55\u5411CSV\u6587\u4ef6\u6dfb\u52a0\u4e00\u884c\u6570\u636e\uff1f<\/strong><br \/>\u8981\u5411CSV\u6587\u4ef6\u6dfb\u52a0\u4e00\u884c\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>csv<\/code>\u6a21\u5757\u3002\u60a8\u53ef\u4ee5\u6253\u5f00\u6587\u4ef6\u5e76\u4f7f\u7528<code>csv.writer<\/code>\u5bf9\u8c61\u7684<code>writerow()<\/code>\u65b9\u6cd5\u3002\u4f8b\u5982\uff0c\u6253\u5f00\u6587\u4ef6\u65f6\u4f7f\u7528<code>with open(&#39;file.csv&#39;, mode=&#39;a&#39;, newline=&#39;&#39;) as file:<\/code>\uff0c\u7136\u540e\u8c03\u7528<code>writer.writerow([&#39;column1&#39;, &#39;column2&#39;, &#39;column3&#39;])<\/code>\u5c06\u65b0\u884c\u5199\u5165\u6587\u4ef6\u3002<\/p>\n<p><strong>\u5728Python\u5b57\u5178\u4e2d\u5982\u4f55\u6dfb\u52a0\u65b0\u7684\u952e\u503c\u5bf9\uff1f<\/strong><br \/>\u5728\u5b57\u5178\u4e2d\u6dfb\u52a0\u65b0\u7684\u952e\u503c\u5bf9\u975e\u5e38\u7b80\u5355\u3002\u60a8\u53ea\u9700\u4f7f\u7528<code>dictionary[key] = value<\/code>\u7684\u8bed\u6cd5\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u6709\u4e00\u4e2a\u5b57\u5178<code>my_dict<\/code>\uff0c\u60f3\u8981\u6dfb\u52a0\u4e00\u4e2a\u65b0\u7684\u952e<code>&#39;new_key&#39;<\/code>\u548c\u5bf9\u5e94\u7684\u503c<code>&#39;new_value&#39;<\/code>\uff0c\u53ea\u9700\u6267\u884c<code>my_dict[&#39;new_key&#39;] = &#39;new_value&#39;<\/code>\u5373\u53ef\u3002\u8fd9\u5c06\u81ea\u52a8\u66f4\u65b0\u5b57\u5178\u5185\u5bb9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u4e2d\u6dfb\u52a0\u4e00\u884c\u6570\u636e\u7684\u65b9\u5f0f\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528\u5217\u8868\u3001\u5b57\u5178\u3001Pandas\u5e93\u7b49\u3002\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u4f7f\u7528Pandas\u5e93 [&hellip;]","protected":false},"author":3,"featured_media":1039007,"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\/1038995"}],"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=1038995"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1038995\/revisions"}],"predecessor-version":[{"id":1039008,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1038995\/revisions\/1039008"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1039007"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1038995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1038995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1038995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}