{"id":1122860,"date":"2025-01-08T19:26:12","date_gmt":"2025-01-08T11:26:12","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1122860.html"},"modified":"2025-01-08T19:26:14","modified_gmt":"2025-01-08T11:26:14","slug":"python%e5%a6%82%e4%bd%95%e5%b0%86%e4%b8%a4%e5%88%97%e6%95%b0%e6%8d%ae%e9%9b%86%e5%af%bc%e5%87%ba","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1122860.html","title":{"rendered":"python\u5982\u4f55\u5c06\u4e24\u5217\u6570\u636e\u96c6\u5bfc\u51fa"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25084538\/4bdde812-8eb6-4def-89bf-fc68a9353ffd.webp\" alt=\"python\u5982\u4f55\u5c06\u4e24\u5217\u6570\u636e\u96c6\u5bfc\u51fa\" \/><\/p>\n<p><p> <strong>Python\u5c06\u4e24\u5217\u6570\u636e\u96c6\u5bfc\u51fa\u7684\u6838\u5fc3\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528Pandas\u5e93\u3001\u4f7f\u7528CSV\u6587\u4ef6\u683c\u5f0f\u3001\u8fdb\u884c\u6570\u636e\u6e05\u6d17\u548c\u683c\u5f0f\u5316\u3002<\/strong> \u5176\u4e2d\uff0c<strong>Pandas\u5e93<\/strong>\u662f\u6700\u4e3a\u5e38\u7528\u4e14\u529f\u80fd\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u5de5\u5177\uff0c\u80fd\u591f\u8f7b\u677e\u5904\u7406\u6570\u636e\u7684\u8bfb\u53d6\u3001\u6e05\u6d17\u548c\u5bfc\u51fa\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u5c55\u5f00\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Pandas\u5e93\u5c06\u4e24\u5217\u6570\u636e\u96c6\u5bfc\u51fa\u3002<\/p>\n<\/p>\n<hr>\n<p><h3>\u4e00\u3001PANDAS\u5e93\u7684\u5b89\u88c5\u4e0e\u5bfc\u5165<\/h3>\n<\/p>\n<p><p>Pandas\u662fPython\u4e2d\u6700\u5e38\u7528\u7684\u6570\u636e\u5904\u7406\u5e93\u4e4b\u4e00\uff0c\u80fd\u591f\u9ad8\u6548\u5730\u5904\u7406\u5404\u79cd\u6570\u636e\u3002\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u7684Python\u73af\u5883\u4e2d\u5df2\u7ecf\u5b89\u88c5\u4e86Pandas\u5e93\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u5bfc\u5165Pandas\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u8bfb\u53d6\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u6570\u636e\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u8bfb\u53d6\u6570\u636e\u3002Pandas\u652f\u6301\u591a\u79cd\u6570\u636e\u683c\u5f0f\uff0c\u5305\u62ecCSV\u3001Excel\u3001SQL\u7b49\u3002\u8fd9\u91cc\u6211\u4eec\u4ee5CSV\u683c\u5f0f\u4e3a\u4f8b\uff0c\u8bfb\u53d6\u4e00\u4e2a\u5305\u542b\u4e24\u5217\u6570\u636e\u7684CSV\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><p>\u5047\u8bbe\u6709\u4e00\u4e2a\u540d\u4e3a<code>data.csv<\/code>\u7684\u6587\u4ef6\uff0c\u6587\u4ef6\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code>column1,column2<\/p>\n<p>1,4<\/p>\n<p>2,5<\/p>\n<p>3,6<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f7f\u7528Pandas\u8bfb\u53d6\u8be5\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = pd.read_csv(&#39;data.csv&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u6570\u636e\u6e05\u6d17\u4e0e\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u5728\u5bfc\u51fa\u6570\u636e\u4e4b\u524d\uff0c\u53ef\u80fd\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u6e05\u6d17\u548c\u5904\u7406\u3002\u6570\u636e\u6e05\u6d17\u7684\u8fc7\u7a0b\u5305\u62ec\u5904\u7406\u7f3a\u5931\u503c\u3001\u91cd\u590d\u503c\u548c\u6570\u636e\u683c\u5f0f\u5316\u7b49\u3002<\/p>\n<\/p>\n<p><h4>1. \u5904\u7406\u7f3a\u5931\u503c<\/h4>\n<\/p>\n<p><p>\u7f3a\u5931\u503c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6570\u636e\u5206\u6790\u7ed3\u679c\u4e0d\u51c6\u786e\uff0c\u56e0\u6b64\u9700\u8981\u5904\u7406\u7f3a\u5931\u503c\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u5904\u7406\u7f3a\u5931\u503c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = data.dropna()  # \u5220\u9664\u5305\u542b\u7f3a\u5931\u503c\u7684\u884c<\/p>\n<h2><strong>\u6216\u8005<\/strong><\/h2>\n<p>data = data.fillna(0)  # \u5c06\u7f3a\u5931\u503c\u586b\u5145\u4e3a0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u5904\u7406\u91cd\u590d\u503c<\/h4>\n<\/p>\n<p><p>\u91cd\u590d\u503c\u4e5f\u53ef\u80fd\u4f1a\u5f71\u54cd\u6570\u636e\u5206\u6790\u7ed3\u679c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\u5904\u7406\u91cd\u590d\u503c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data = data.drop_duplicates()  # \u5220\u9664\u91cd\u590d\u884c<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3. \u6570\u636e\u683c\u5f0f\u5316<\/h4>\n<\/p>\n<p><p>\u6709\u65f6\u5019\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u683c\u5f0f\u5316\uff0c\u4f8b\u5982\u5c06\u6570\u636e\u7c7b\u578b\u8f6c\u6362\u4e3a\u7279\u5b9a\u7c7b\u578b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data[&#39;column1&#39;] = data[&#39;column1&#39;].astype(int)  # \u5c06&#39;column1&#39;\u8f6c\u6362\u4e3a\u6574\u6570\u7c7b\u578b<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u6570\u636e\u5bfc\u51fa<\/h3>\n<\/p>\n<p><p>\u6570\u636e\u5904\u7406\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5c06\u6570\u636e\u5bfc\u51fa\u4e3aCSV\u6587\u4ef6\u6216\u5176\u4ed6\u683c\u5f0f\u3002\u8fd9\u91cc\u6211\u4eec\u4ee5\u5bfc\u51fa\u4e3aCSV\u6587\u4ef6\u4e3a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data.to_csv(&#39;output.csv&#39;, index=False)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\uff0c\u5904\u7406\u540e\u7684\u6570\u636e\u5c06\u88ab\u5bfc\u51fa\u5230<code>output.csv<\/code>\u6587\u4ef6\u4e2d\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u4f7f\u7528Excel\u683c\u5f0f\u5bfc\u51fa<\/h3>\n<\/p>\n<p><p>\u9664\u4e86CSV\u683c\u5f0f\uff0cPandas\u8fd8\u652f\u6301\u5c06\u6570\u636e\u5bfc\u51fa\u4e3aExcel\u683c\u5f0f\u3002\u9700\u8981\u5b89\u88c5<code>openpyxl<\/code>\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install openpyxl<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u5bfc\u51fa\u6570\u636e\u4e3aExcel\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">data.to_excel(&#39;output.xlsx&#39;, index=False)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u516d\u3001\u4f7f\u7528SQL\u6570\u636e\u5e93\u5bfc\u51fa<\/h3>\n<\/p>\n<p><p>Pandas\u8fd8\u652f\u6301\u5c06\u6570\u636e\u5bfc\u51fa\u5230SQL\u6570\u636e\u5e93\u4e2d\u3002\u9700\u8981\u5b89\u88c5<code>SQLAlchemy<\/code>\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install sqlalchemy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u5c06\u6570\u636e\u5bfc\u51fa\u5230SQL\u6570\u636e\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sqlalchemy import create_engine<\/p>\n<h2><strong>\u521b\u5efa\u6570\u636e\u5e93\u8fde\u63a5<\/strong><\/h2>\n<p>engine = create_engine(&#39;sqlite:\/\/\/output.db&#39;)<\/p>\n<h2><strong>\u5c06\u6570\u636e\u5bfc\u51fa\u5230SQL\u6570\u636e\u5e93<\/strong><\/h2>\n<p>data.to_sql(&#39;table_name&#39;, engine, index=False)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e03\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u4f7f\u7528Pandas\u5e93\u5c06\u4e24\u5217\u6570\u636e\u96c6\u5bfc\u51fa\u4e3a\u4e0d\u540c\u7684\u683c\u5f0f\u3002\u5728\u6570\u636e\u5904\u7406\u8fc7\u7a0b\u4e2d\uff0c<strong>\u6570\u636e\u6e05\u6d17\u548c\u683c\u5f0f\u5316<\/strong>\u662f\u975e\u5e38\u91cd\u8981\u7684\u6b65\u9aa4\uff0c\u80fd\u591f\u786e\u4fdd\u5bfc\u51fa\u7684\u6570\u636e\u51c6\u786e\u65e0\u8bef\u3002\u65e0\u8bba\u662f\u5bfc\u51fa\u4e3aCSV\u3001Excel\u8fd8\u662fSQL\u6570\u636e\u5e93\uff0cPandas\u90fd\u63d0\u4f9b\u4e86\u7b80\u4fbf\u7684\u65b9\u6cd5\u6765\u5904\u7406\u548c\u5bfc\u51fa\u6570\u636e\u3002<\/p>\n<\/p>\n<hr>\n<p><h3>\u516b\u3001\u9644\u52a0\u5185\u5bb9\uff1a\u4f7f\u7528Numpy\u8fdb\u884c\u6570\u636e\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u9664\u4e86Pandas\uff0cNumpy\u4e5f\u662f\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u5e93\uff0c\u7279\u522b\u662f\u5728\u5904\u7406\u6570\u503c\u8ba1\u7b97\u65f6\u3002\u53ef\u4ee5\u4e0ePandas\u7ed3\u5408\u4f7f\u7528\uff0c\u63d0\u5347\u6570\u636e\u5904\u7406\u6548\u7387\u3002<\/p>\n<\/p>\n<p><h4>1. \u5b89\u88c5\u4e0e\u5bfc\u5165Numpy<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">pip install numpy<\/p>\n<p>import numpy as np<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u751f\u6210\u6570\u636e\u5e76\u8f6c\u6362\u4e3aPandas DataFrame<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\"># \u751f\u6210\u968f\u673a\u6570\u636e<\/p>\n<p>data_array = np.random.rand(10, 2)  # \u751f\u621010\u884c2\u5217\u7684\u968f\u673a\u6570<\/p>\n<h2><strong>\u8f6c\u6362\u4e3aPandas DataFrame<\/strong><\/h2>\n<p>data = pd.DataFrame(data_array, columns=[&#39;column1&#39;, &#39;column2&#39;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3. \u6570\u636e\u5904\u7406\u4e0e\u5bfc\u51fa<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528\u4e0e\u524d\u8ff0\u76f8\u540c\u7684\u65b9\u6cd5\u5bf9\u6570\u636e\u8fdb\u884c\u6e05\u6d17\u3001\u5904\u7406\u548c\u5bfc\u51fa\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6e05\u6d17\u4e0e\u5904\u7406<\/p>\n<p>data = data.dropna().drop_duplicates()<\/p>\n<p>data[&#39;column1&#39;] = data[&#39;column1&#39;].astype(float)<\/p>\n<h2><strong>\u5bfc\u51fa<\/strong><\/h2>\n<p>data.to_csv(&#39;output.csv&#39;, index=False)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528Numpy\u751f\u6210\u6570\u636e\uff0c\u5e76\u7ed3\u5408Pandas\u8fdb\u884c\u6570\u636e\u5904\u7406\u548c\u5bfc\u51fa\u3002<\/p>\n<\/p>\n<hr>\n<p><h3>\u4e5d\u3001\u9644\u52a0\u5185\u5bb9\uff1a\u6570\u636e\u53ef\u89c6\u5316<\/h3>\n<\/p>\n<p><p>\u5728\u6570\u636e\u5904\u7406\u8fc7\u7a0b\u4e2d\uff0c\u6570\u636e\u53ef\u89c6\u5316\u662f\u975e\u5e38\u91cd\u8981\u7684\u4e00\u73af\uff0c\u80fd\u591f\u5e2e\u52a9\u6211\u4eec\u76f4\u89c2\u5730\u7406\u89e3\u6570\u636e\u3002Python\u4e2d\u6709\u5f88\u591a\u6570\u636e\u53ef\u89c6\u5316\u5e93\uff0c\u4f8b\u5982Matplotlib\u548cSeaborn\u3002<\/p>\n<\/p>\n<p><h4>1. \u5b89\u88c5\u4e0e\u5bfc\u5165Matplotlib\u548cSeaborn<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">pip install matplotlib seaborn<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<p>import seaborn as sns<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u7ed8\u5236\u6570\u636e\u56fe\u8868<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528Matplotlib\u548cSeaborn\u7ed8\u5236\u6570\u636e\u56fe\u8868\uff0c\u5e2e\u52a9\u7406\u89e3\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u7ed8\u5236\u6563\u70b9\u56fe<\/p>\n<p>plt.figure(figsize=(10, 6))<\/p>\n<p>sns.scatterplot(x=&#39;column1&#39;, y=&#39;column2&#39;, data=data)<\/p>\n<p>plt.title(&#39;Scatter Plot of Column1 vs Column2&#39;)<\/p>\n<p>plt.xlabel(&#39;Column1&#39;)<\/p>\n<p>plt.ylabel(&#39;Column2&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528Matplotlib\u548cSeaborn\u5bf9\u6570\u636e\u8fdb\u884c\u53ef\u89c6\u5316\uff0c\u5e2e\u52a9\u7406\u89e3\u6570\u636e\u7279\u5f81\u548c\u5173\u7cfb\u3002<\/p>\n<\/p>\n<hr>\n<p><p>\u603b\u7ed3\u4ee5\u4e0a\u5185\u5bb9\uff0c\u901a\u8fc7\u4f7f\u7528Pandas\u5e93\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u4e24\u5217\u6570\u636e\u96c6\u5bfc\u51fa\u4e3a\u4e0d\u540c\u7684\u683c\u5f0f\uff0c\u5e76\u4e14\u901a\u8fc7\u6570\u636e\u6e05\u6d17\u3001\u5904\u7406\u548c\u53ef\u89c6\u5316\uff0c\u786e\u4fdd\u6570\u636e\u7684\u51c6\u786e\u6027\u548c\u53ef\u7406\u89e3\u6027\u3002\u7ed3\u5408Numpy\u3001Matplotlib\u548cSeaborn\u7b49\u5176\u4ed6\u5e93\uff0c\u53ef\u4ee5\u8fdb\u4e00\u6b65\u63d0\u5347\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u7684\u6548\u7387\u548c\u6548\u679c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5c06\u4e24\u5217\u6570\u636e\u96c6\u5bfc\u51fa\u4e3aCSV\u6587\u4ef6\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528pandas\u5e93\u6765\u5904\u7406\u6570\u636e\u96c6\u5e76\u5c06\u5176\u5bfc\u51fa\u4e3aCSV\u6587\u4ef6\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u4e24\u5217\u7684DataFrame\uff0c\u7136\u540e\u4f7f\u7528<code>to_csv()<\/code>\u65b9\u6cd5\u5c06\u5176\u5bfc\u51fa\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-python\">import pandas as pd\n\ndata = {\n    &#39;\u52171&#39;: [1, 2, 3],\n    &#39;\u52172&#39;: [&#39;A&#39;, &#39;B&#39;, &#39;C&#39;]\n}\ndf = pd.DataFrame(data)\ndf.to_csv(&#39;output.csv&#39;, index=False)\n<\/code><\/pre>\n<p>\u8fd9\u6837\u5c31\u4f1a\u751f\u6210\u4e00\u4e2a\u540d\u4e3a<code>output.csv<\/code>\u7684\u6587\u4ef6\uff0c\u5305\u542b\u60a8\u6307\u5b9a\u7684\u4e24\u5217\u6570\u636e\u3002<\/p>\n<p><strong>\u5982\u4f55\u9009\u62e9\u7279\u5b9a\u7684\u5217\u8fdb\u884c\u5bfc\u51fa\uff1f<\/strong><br \/>\u5982\u679c\u60a8\u7684\u6570\u636e\u96c6\u4e2d\u5305\u542b\u591a\u4e8e\u4e24\u5217\uff0c\u60a8\u53ef\u4ee5\u5728\u5bfc\u51fa\u4e4b\u524d\u9009\u62e9\u7279\u5b9a\u7684\u5217\u3002\u4f7f\u7528DataFrame\u7684\u5217\u9009\u62e9\u529f\u80fd\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-python\">selected_columns = df[[&#39;\u52171&#39;, &#39;\u52172&#39;]]\nselected_columns.to_csv(&#39;selected_output.csv&#39;, index=False)\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5c06\u4ec5\u5bfc\u51fa\u201c\u52171\u201d\u548c\u201c\u52172\u201d\u5230\u4e00\u4e2a\u65b0\u7684CSV\u6587\u4ef6\u4e2d\u3002<\/p>\n<p><strong>\u5bfc\u51fa\u65f6\u5982\u4f55\u5904\u7406\u7f3a\u5931\u503c\uff1f<\/strong><br \/>\u5728\u5bfc\u51fa\u6570\u636e\u96c6\u65f6\uff0c\u60a8\u53ef\u80fd\u4f1a\u9047\u5230\u7f3a\u5931\u503c\u3002pandas\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u5904\u7406\u7f3a\u5931\u503c\uff0c\u4f8b\u5982\u4f7f\u7528<code>fillna()<\/code>\u65b9\u6cd5\u586b\u5145\u7f3a\u5931\u6570\u636e\u3002\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">df.fillna(&#39;\u7f3a\u5931\u503c&#39;, inplace=True)  # \u5c06\u7f3a\u5931\u503c\u66ff\u6362\u4e3a&#39;\u7f3a\u5931\u503c&#39;\ndf.to_csv(&#39;output_with_na.csv&#39;, index=False)\n<\/code><\/pre>\n<p>\u8fd9\u6837\u5904\u7406\u540e\uff0c\u5bfc\u51fa\u7684CSV\u6587\u4ef6\u5c06\u4e0d\u4f1a\u5305\u542bNaN\u503c\uff0c\u786e\u4fdd\u6570\u636e\u5b8c\u6574\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u5c06\u4e24\u5217\u6570\u636e\u96c6\u5bfc\u51fa\u7684\u6838\u5fc3\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528Pandas\u5e93\u3001\u4f7f\u7528CSV\u6587\u4ef6\u683c\u5f0f\u3001\u8fdb\u884c\u6570\u636e\u6e05\u6d17\u548c\u683c\u5f0f\u5316\u3002 \u5176 [&hellip;]","protected":false},"author":3,"featured_media":1122864,"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\/1122860"}],"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=1122860"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1122860\/revisions"}],"predecessor-version":[{"id":1122866,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1122860\/revisions\/1122866"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1122864"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1122860"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1122860"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1122860"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}