{"id":303883,"date":"2024-05-20T19:09:56","date_gmt":"2024-05-20T11:09:56","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/303883.html"},"modified":"2024-05-20T19:10:15","modified_gmt":"2024-05-20T11:10:15","slug":"python-%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-pandas-%e5%a4%84%e7%90%86-dataframe","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/303883.html","title":{"rendered":"python \u5982\u4f55\u4f7f\u7528 pandas \u5904\u7406 dataFrame"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/26220142\/e99af51c-95dd-48fd-a0f6-bd47abc43808.webp\" alt=\"python \u5982\u4f55\u4f7f\u7528 pandas \u5904\u7406 dataFrame\" \/><\/p>\n<p><p><strong>Python\u4f7f\u7528Pandas\u5904\u7406DataFrame\u7684\u65b9\u5f0f\u5305\u62ec\u9009\u62e9\u4e0e\u7d22\u5f15\u6570\u636e\u3001\u6570\u636e\u6e05\u6d17\u3001\u6570\u636e\u8f6c\u6362\u548c\u7edf\u8ba1\u5206\u6790\u7b49<\/strong>\u3002Pandas\u662fPython\u4e2d\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u5de5\u5177\uff0c\u5b83\u63d0\u4f9b\u4e86DataFrame\u5bf9\u8c61\u6765\u5b58\u50a8\u548c\u64cd\u4f5c\u7ed3\u6784\u5316\u6570\u636e\u3002DataFrame\u662f\u4e00\u4e2a\u4e8c\u7ef4\u3001\u5927\u5c0f\u53ef\u53d8\u4e14\u6f5c\u5728\u7684\u5f02\u6784\u7684\u8868\u683c\u6570\u636e\u7ed3\u6784\uff0c\u6709\u5e26\u6807\u7b7e\u7684\u8f74\uff08\u884c\u548c\u5217\uff09\u3002\u4e3a\u4e86\u9ad8\u6548\u5730\u4f7f\u7528Pandas\u5e93\u5904\u7406DataFrame\uff0c\u53ef\u4ee5\u91c7\u53d6\u4e00\u7cfb\u5217\u65b9\u6cd5\uff0c\u5982\u4f7f\u7528\u6761\u4ef6\u9009\u62e9\u6765\u8fc7\u6ee4\u6570\u636e\u3001\u5229\u7528groupby\u65b9\u6cd5\u8fdb\u884c\u6570\u636e\u5206\u7ec4\u3001\u6267\u884cmerge\u548cjoin\u64cd\u4f5c\u6765\u5408\u5e76\u6570\u636e\uff0c\u4ee5\u53ca\u4f7f\u7528Pandas\u7684\u5185\u7f6e\u7edf\u8ba1\u51fd\u6570\u6765\u8fdb\u884c\u6570\u636e\u5206\u6790\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u9009\u62e9\u4e0e\u7d22\u5f15\u6570\u636e<\/h2>\n<\/p>\n<p><p>Pandas\u63d0\u4f9b\u591a\u79cd\u65b9\u6cd5\u6765\u9009\u62e9\u548c\u7d22\u5f15DataFrame\u4e2d\u7684\u6570\u636e\uff0c\u5305\u62ec\u4f7f\u7528\u6807\u7b7e\u7d22\u5f15\uff08loc\uff09\u548c\u4f4d\u7f6e\u7d22\u5f15\uff08iloc\uff09\u3002<\/p>\n<\/p>\n<p><h3><strong>\u9009\u62e9\u7279\u5b9a\u7684\u5217\u6216\u884c<\/strong><\/h3>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u793a\u4f8bDataFrame<\/strong><\/h2>\n<p>data = {&#039;Name&#039;: [&#039;John&#039;, &#039;Anna&#039;, &#039;Peter&#039;, &#039;Linda&#039;],<\/p>\n<p>        &#039;Age&#039;: [28, 23, 34, 29],<\/p>\n<p>        &#039;City&#039;: [&#039;New York&#039;, &#039;Paris&#039;, &#039;Berlin&#039;, &#039;London&#039;]}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u9009\u62e9\u5177\u4f53\u7684\u4e00\u5217<\/strong><\/h2>\n<p>ages = df[&#039;Age&#039;]<\/p>\n<h2><strong>\u9009\u62e9\u591a\u5217<\/strong><\/h2>\n<p>subset = df[[&#039;Name&#039;, &#039;City&#039;]]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3><strong>\u4f7f\u7528\u6761\u4ef6\u8868\u8fbe\u5f0f\u8fdb\u884c\u7b5b\u9009<\/strong><\/h3>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6761\u4ef6\u9009\u62e9\u5e74\u9f84\u5927\u4e8e30\u7684\u4eba<\/p>\n<p>older_than_30 = df[df[&#039;Age&#039;] &gt; 30]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e8c\u3001\u6570\u636e\u6e05\u6d17<\/h2>\n<\/p>\n<p><p>\u5728\u771f\u5b9e\u4e16\u754c\u7684\u6570\u636e\u5206\u6790\u4efb\u52a1\u4e2d\uff0c\u6570\u636e\u6e05\u6d17\u662f\u6700\u91cd\u8981\u7684\u6b65\u9aa4\u4e4b\u4e00\u3002\u8fd9\u901a\u5e38\u5305\u62ec\u5904\u7406\u7f3a\u5931\u503c\u3001\u53bb\u9664\u91cd\u590d\u6570\u636e\u7b49\u3002<\/p>\n<\/p>\n<p><h3><strong>\u5904\u7406\u7f3a\u5931\u503c<\/strong><\/h3>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5047\u8bbeDataFrame\u5b58\u5728\u7f3a\u5931\u503c<\/p>\n<p>df[&#039;Salary&#039;] = pd.Series([3000, None, 5000, 4500])<\/p>\n<h2><strong>\u586b\u5145\u7f3a\u5931\u503c<\/strong><\/h2>\n<p>df_filled = df.fillna({&#039;Salary&#039;: df[&#039;Salary&#039;].mean()})<\/p>\n<h2><strong>\u5220\u9664\u6709\u7f3a\u5931\u503c\u7684\u884c<\/strong><\/h2>\n<p>df_dropped = df.dropna()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3><strong>\u53bb\u9664\u91cd\u590d\u6570\u636e<\/strong><\/h3>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5220\u9664\u91cd\u590d\u6570\u636e<\/p>\n<p>df = df.drop_duplicates()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e09\u3001\u6570\u636e\u8f6c\u6362<\/h2>\n<\/p>\n<p><p>\u6570\u636e\u8f6c\u6362\u80fd\u591f\u5e2e\u52a9\u6211\u4eec\u5bf9\u6570\u636e\u8fdb\u884c\u52a0\u5de5\uff0c\u4ee5\u4fbf\u4e8e\u66f4\u597d\u5730\u8fdb\u884c\u5206\u6790\u4e0e\u53ef\u89c6\u5316\u3002<\/p>\n<\/p>\n<p><h3><strong>\u8f6c\u6362\u6570\u636e\u7c7b\u578b<\/strong><\/h3>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5c06&#039;Age&#039;\u5217\u8f6c\u6362\u4e3afloat\u7c7b\u578b<\/p>\n<p>df[&#039;Age&#039;] = df[&#039;Age&#039;].astype(float)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3><strong>\u4f7f\u7528\u51fd\u6570\u6216\u6620\u5c04\u8fdb\u884c\u6570\u636e\u8f6c\u6362<\/strong><\/h3>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528apply\u51fd\u6570\u5bf9\u6570\u636e\u8fdb\u884c\u8f6c\u6362<\/p>\n<p>df[&#039;Age_in_days&#039;] = df[&#039;Age&#039;].apply(lambda x: x * 365)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u56db\u3001\u7edf\u8ba1\u5206\u6790<\/h2>\n<\/p>\n<p><p>Pandas\u5185\u7f6e\u4e86\u4e30\u5bcc\u7684\u7edf\u8ba1\u51fd\u6570\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5bf9\u6570\u636e\u8fdb\u884c\u63cf\u8ff0\u6027\u5206\u6790\u3002<\/p>\n<\/p>\n<p><h3><strong>\u57fa\u672c\u7684\u63cf\u8ff0\u7edf\u8ba1<\/strong><\/h3>\n<\/p>\n<p><pre><code class=\"language-python\"># \u83b7\u53d6\u63cf\u8ff0\u6027\u7edf\u8ba1\u4fe1\u606f<\/p>\n<p>description = df.describe()<\/p>\n<h2><strong>\u8ba1\u7b97\u7279\u5b9a\u5217\u7684\u5747\u503c<\/strong><\/h2>\n<p>average_age = df[&#039;Age&#039;].mean()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3><strong>\u5206\u7ec4\u4e0e\u805a\u5408<\/strong><\/h3>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6309\u7167\u57ce\u5e02\u5206\u7ec4\uff0c\u8ba1\u7b97\u6bcf\u4e2a\u57ce\u5e02\u7684\u5e73\u5747\u5e74\u9f84<\/p>\n<p>grouped = df.groupby(&#039;City&#039;).agg({&#039;Age&#039;: &#039;mean&#039;})<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e94\u3001\u6570\u636e\u5408\u5e76<\/h2>\n<\/p>\n<p><p>\u5408\u5e76\u64cd\u4f5c\u5141\u8bb8\u5c06\u4e0d\u540c\u7684\u6570\u636e\u96c6\u6309\u7279\u5b9a\u7684\u903b\u8f91\u62fc\u63a5\u5728\u4e00\u8d77\u3002<\/p>\n<\/p>\n<p><h3><strong>\u4f7f\u7528concat\u5408\u5e76\u6570\u636e<\/strong><\/h3>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5047\u8bbe\u6709\u53e6\u4e00\u4e2aDataFrame<\/p>\n<p>data2 = {&#039;Name&#039;: [&#039;Sara&#039;, &#039;Tom&#039;],<\/p>\n<p>         &#039;Age&#039;: [25, 31],<\/p>\n<p>         &#039;City&#039;: [&#039;Rome&#039;, &#039;Sydney&#039;]}<\/p>\n<p>df2 = pd.DataFrame(data2)<\/p>\n<h2><strong>\u7eb5\u5411\u5408\u5e76\u4e24\u4e2aDataFrame<\/strong><\/h2>\n<p>df_concatenated = pd.concat([df, df2], ignore_index=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3><strong>\u4f7f\u7528merge\u8fdb\u884c\u8fde\u63a5<\/strong><\/h3>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5982\u679c\u6709\u4e00\u4e2a\u5305\u542b\u57ce\u5e02\u5de5\u8d44\u7edf\u8ba1\u7684DataFrame<\/p>\n<p>city_data = pd.DataFrame({&#039;City&#039;: [&#039;New York&#039;, &#039;Berlin&#039;],<\/p>\n<p>                          &#039;Average Salary&#039;: [70000, 55000]})<\/p>\n<h2><strong>\u5c06city_data\u4e0edf\u6309\u7167\u57ce\u5e02\u8fdb\u884c\u5408\u5e76<\/strong><\/h2>\n<p>df_merged = pd.merge(df, city_data, on=&#039;City&#039;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4f7f\u7528\u4e0a\u8ff0\u6280\u672f\uff0cPython\u548cPandas\u80fd\u591f\u7075\u6d3b\u5730\u5904\u7406DataFrame\uff0c\u8ba9\u590d\u6742\u7684\u6570\u636e\u5206\u6790\u548c\u5904\u7406\u53d8\u5f97\u7b80\u5355\u6613\u884c\u3002\u901a\u8fc7\u9010\u6b65\u638c\u63e1Pandas\u5e93\u7684\u5f3a\u5927\u529f\u80fd\uff0c\u4f60\u53ef\u4ee5\u6781\u5927\u5730\u63d0\u9ad8\u6570\u636e\u5904\u7406\u7684\u6548\u7387\u53ca\u8d28\u91cf\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. \u5982\u4f55\u4f7f\u7528pandas\u5904\u7406DataFrame?<\/strong><\/p>\n<p>Pandas\u662f\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684Python\u5e93\uff0c\u7528\u4e8e\u5904\u7406\u548c\u5206\u6790\u6570\u636e\u3002\u8981\u4f7f\u7528pandas\u5904\u7406DataFrame\u5bf9\u8c61\uff0c\u9996\u5148\u9700\u8981\u5bfc\u5165pandas\u5e93\u3002\u7136\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528pandas\u7684\u5404\u79cd\u65b9\u6cd5\u548c\u51fd\u6570\u8fdb\u884c\u6570\u636e\u64cd\u4f5c\u548c\u8f6c\u6362\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u8bfb\u53d6\u4e00\u4e2aCSV\u6587\u4ef6\u5e76\u5c06\u5176\u8f6c\u6362\u4e3aDataFrame\uff0c\u53ef\u4ee5\u4f7f\u7528pandas\u4e2d\u7684<code>read_csv()<\/code>\u51fd\u6570\u3002\u8fd9\u5c06\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u6587\u4ef6\u6570\u636e\u7684DataFrame\u5bf9\u8c61\u3002\u63a5\u4e0b\u6765\uff0c\u53ef\u4ee5\u4f7f\u7528DataFrame\u7684\u5404\u79cd\u65b9\u6cd5\uff0c\u5982<code>head()<\/code>\u3001<code>t<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>l()<\/code>\u3001<code>describe()<\/code>\u7b49\u6765\u67e5\u770b\u6570\u636e\u7684\u524d\u51e0\u884c\u3001\u540e\u51e0\u884c\u4ee5\u53ca\u57fa\u672c\u7edf\u8ba1\u4fe1\u606f\u3002<\/p>\n<p>\u5f53\u7136\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528pandas\u63d0\u4f9b\u7684\u8bb8\u591a\u529f\u80fd\u6765\u5bf9DataFrame\u8fdb\u884c\u64cd\u4f5c\uff0c\u5982\u9009\u62e9\u7279\u5b9a\u7684\u5217\u3001\u6dfb\u52a0\u65b0\u5217\u3001\u8fc7\u6ee4\u6570\u636e\u3001\u5bf9\u6570\u636e\u8fdb\u884c\u6392\u5e8f\u3001\u5904\u7406\u7f3a\u5931\u503c\u7b49\u3002\u6b64\u5916\uff0cpandas\u8fd8\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u53ef\u89c6\u5316\u5de5\u5177\uff0c\u53ef\u4ee5\u5e2e\u52a9\u60a8\u66f4\u597d\u5730\u7406\u89e3\u548c\u5448\u73b0\u6570\u636e\u3002<\/p>\n<p>\u603b\u800c\u8a00\u4e4b\uff0c\u4f7f\u7528pandas\u5904\u7406DataFrame\u5bf9\u8c61\u975e\u5e38\u7b80\u5355\u548c\u7075\u6d3b\u3002\u5b83\u63d0\u4f9b\u4e86\u8bb8\u591a\u529f\u80fd\u548c\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6ee1\u8db3\u60a8\u5bf9\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u7684\u5404\u79cd\u9700\u6c42\u3002<\/p>\n<p><strong>2. \u5982\u4f55\u4f7f\u7528python\u4e2d\u7684pandas\u5e93\u5904\u7406DataFrame\u5bf9\u8c61?<\/strong><\/p>\n<p>\u5982\u679c\u4f60\u60f3\u4f7f\u7528python\u4e2d\u7684pandas\u5e93\u5904\u7406DataFrame\u5bf9\u8c61\uff0c\u4e0b\u9762\u662f\u4e00\u4e9b\u57fa\u672c\u7684\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>\n<p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u5bfc\u5165pandas\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\u5bfc\u5165pandas\uff1a<\/p>\n<pre><code>import pandas as pd\n<\/code><\/pre>\n<\/li>\n<li>\n<p>\u63a5\u4e0b\u6765\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528pandas\u7684<code>read_csv()<\/code>\u51fd\u6570\u6765\u8bfb\u53d6\u4e00\u4e2aCSV\u6587\u4ef6\uff0c\u5e76\u5c06\u5176\u8f6c\u6362\u4e3aDataFrame\u5bf9\u8c61\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>df = pd.read_csv(&#039;data.csv&#039;)\n<\/code><\/pre>\n<p>\u8fd9\u5c06\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>df<\/code>\u7684DataFrame\u5bf9\u8c61\uff0c\u5176\u4e2d\u5305\u542b\u6765\u81ea<code>data.csv<\/code>\u6587\u4ef6\u7684\u6570\u636e\u3002<\/p>\n<\/li>\n<li>\n<p>\u4e00\u65e6\u4f60\u6709\u4e86DataFrame\u5bf9\u8c61\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u5404\u79cdpandas\u7684\u65b9\u6cd5\u548c\u51fd\u6570\u6765\u64cd\u4f5c\u548c\u8f6c\u6362\u6570\u636e\u3002\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528<code>head()<\/code>\u65b9\u6cd5\u67e5\u770bDataFrame\u7684\u524d\u51e0\u884c\u6570\u636e\uff1a\n<pre><code>df.head()\n<\/code><\/pre>\n<\/li>\n<li>\u4f7f\u7528<code>describe()<\/code>\u65b9\u6cd5\u83b7\u53d6\u6570\u636e\u7684\u57fa\u672c\u7edf\u8ba1\u4fe1\u606f\uff1a\n<pre><code>df.describe()\n<\/code><\/pre>\n<\/li>\n<li>\u4f7f\u7528<code>groupby()<\/code>\u65b9\u6cd5\u5bf9\u6570\u636e\u8fdb\u884c\u5206\u7ec4\uff1a\n<pre><code>df.groupby(&#039;category&#039;).sum()\n<\/code><\/pre>\n<\/li>\n<\/ul>\n<p>\u7b49\u7b49\u3002<\/p>\n<\/li>\n<li>\n<p>\u6700\u540e\uff0c\u8bb0\u5f97\u4fdd\u5b58\u548c\u5bfc\u51fa\u5904\u7406\u540e\u7684\u6570\u636e\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528<code>to_csv()<\/code>\u65b9\u6cd5\u5c06DataFrame\u4fdd\u5b58\u4e3aCSV\u6587\u4ef6\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u76f8\u5173\u65b9\u6cd5\u5bfc\u51fa\u4e3aExcel\u6587\u4ef6\u3001\u6570\u636e\u5e93\u7b49\u3002<\/p>\n<\/li>\n<\/ol>\n<p>\u8fd9\u53ea\u662f\u4f7f\u7528pandas\u5904\u7406DataFrame\u7684\u57fa\u672c\u6b65\u9aa4\uff0c\u5b9e\u9645\u4e0a\u5b83\u63d0\u4f9b\u4e86\u5f88\u591a\u5f3a\u5927\u7684\u529f\u80fd\u548c\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6ee1\u8db3\u60a8\u5bf9\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u7684\u5404\u79cd\u9700\u6c42\u3002<\/p>\n<p><strong>3. \u5728Python\u4e2d\u4f7f\u7528pandas\u5e93\u5904\u7406DataFrame\u7684\u65b9\u6cd5\u6709\u54ea\u4e9b\uff1f<\/strong><\/p>\n<p>\u8981\u5728Python\u4e2d\u4f7f\u7528pandas\u5e93\u5904\u7406DataFrame\u5bf9\u8c61\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<ol>\n<li>\n<p>\u8bfb\u53d6\u6570\u636e\uff1a\u4f7f\u7528<code>read_csv()<\/code>\u51fd\u6570\u8bfb\u53d6CSV\u6587\u4ef6\uff0c\u5c06\u5176\u8f6c\u6362\u4e3aDataFrame\u5bf9\u8c61\u3002\u53ef\u4ee5\u4f7f\u7528<code>read_excel()<\/code>\u51fd\u6570\u8bfb\u53d6Excel\u6587\u4ef6\uff0c\u4f7f\u7528<code>read_sql()<\/code>\u51fd\u6570\u8bfb\u53d6\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u7b49\u3002<\/p>\n<\/li>\n<li>\n<p>\u67e5\u770b\u6570\u636e\uff1a\u4f7f\u7528<code>head()<\/code>\u65b9\u6cd5\u67e5\u770bDataFrame\u7684\u524d\u51e0\u884c\u6570\u636e\uff0c\u9ed8\u8ba4\u663e\u793a\u524d5\u884c\u3002\u4f7f\u7528<code>tail()<\/code>\u65b9\u6cd5\u67e5\u770bDataFrame\u7684\u540e\u51e0\u884c\u6570\u636e\uff0c\u9ed8\u8ba4\u4e5f\u662f\u663e\u793a5\u884c\u3002\u8fd8\u53ef\u4ee5\u4f7f\u7528<code>sample()<\/code>\u65b9\u6cd5\u968f\u673a\u67e5\u770b\u6570\u636e\u7684\u6837\u672c\u3002<\/p>\n<\/li>\n<li>\n<p>\u6570\u636e\u6e05\u6d17\uff1a\u4f7f\u7528<code>dropna()<\/code>\u65b9\u6cd5\u5220\u9664\u542b\u6709\u7f3a\u5931\u503c\u7684\u884c\u6216\u5217\uff1b\u4f7f\u7528<code>fillna()<\/code>\u65b9\u6cd5\u586b\u5145\u7f3a\u5931\u503c\uff1b\u4f7f\u7528<code>drop_duplicates()<\/code>\u65b9\u6cd5\u5220\u9664\u91cd\u590d\u7684\u884c\u7b49\u3002<\/p>\n<\/li>\n<li>\n<p>\u6570\u636e\u9009\u62e9\u548c\u5207\u7247\uff1a\u4f7f\u7528\u65b9\u62ec\u53f7\u64cd\u4f5c\u7b26<code>[]<\/code>\u9009\u62e9\u7279\u5b9a\u7684\u5217\uff1b\u4f7f\u7528<code>loc[]<\/code>\u548c<code>iloc[]<\/code>\u9009\u62e9\u7279\u5b9a\u7684\u884c\u6216\u4f4d\u7f6e\uff1b\u4f7f\u7528\u6761\u4ef6\u8fc7\u6ee4\u9009\u62e9\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u7684\u884c\u7b49\u3002<\/p>\n<\/li>\n<li>\n<p>\u6570\u636e\u6392\u5e8f\uff1a\u4f7f\u7528<code>sort_values()<\/code>\u65b9\u6cd5\u6309\u7167\u6307\u5b9a\u7684\u5217\u8fdb\u884c\u6392\u5e8f\uff0c\u9ed8\u8ba4\u662f\u5347\u5e8f\u6392\u5e8f\u3002\u53ef\u4ee5\u4f7f\u7528<code>ascending=False<\/code>\u53c2\u6570\u8fdb\u884c\u964d\u5e8f\u6392\u5e8f\u3002<\/p>\n<\/li>\n<li>\n<p>\u6570\u636e\u805a\u5408\u548c\u5206\u7ec4\uff1a\u4f7f\u7528<code>groupby()<\/code>\u65b9\u6cd5\u8fdb\u884c\u6570\u636e\u5206\u7ec4\uff0c\u5e76\u4f7f\u7528\u805a\u5408\u51fd\u6570\uff08\u4f8b\u5982<code>sum()<\/code>\u3001<code>mean()<\/code>\u3001<code>count()<\/code>\u7b49\uff09\u5bf9\u5206\u7ec4\u540e\u7684\u6570\u636e\u8fdb\u884c\u8ba1\u7b97\u3002<\/p>\n<\/li>\n<li>\n<p>\u6570\u636e\u5408\u5e76\u548c\u62fc\u63a5\uff1a\u53ef\u4ee5\u4f7f\u7528<code>concat()<\/code>\u51fd\u6570\u5c06\u591a\u4e2aDataFrame\u5bf9\u8c61\u6309\u884c\u6216\u5217\u65b9\u5411\u8fdb\u884c\u5408\u5e76\uff1b\u53ef\u4ee5\u4f7f\u7528<code>merge()<\/code>\u51fd\u6570\u6839\u636e\u6307\u5b9a\u7684\u5217\u5c06\u591a\u4e2aDataFrame\u5bf9\u8c61\u8fdb\u884c\u62fc\u63a5\u3002<\/p>\n<\/li>\n<\/ol>\n<p>\u603b\u4e4b\uff0c\u4ee5\u4e0a\u4ec5\u662f\u4f7f\u7528pandas\u5904\u7406DataFrame\u7684\u4e00\u4e9b\u5e38\u7528\u65b9\u6cd5\u3002pandas\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u548c\u65b9\u6cd5\uff0c\u53ef\u4ee5\u7075\u6d3b\u5904\u7406\u5404\u79cd\u6570\u636e\u64cd\u4f5c\u548c\u8f6c\u6362\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u4f7f\u7528Pandas\u5904\u7406DataFrame\u7684\u65b9\u5f0f\u5305\u62ec\u9009\u62e9\u4e0e\u7d22\u5f15\u6570\u636e\u3001\u6570\u636e\u6e05\u6d17\u3001\u6570\u636e\u8f6c\u6362\u548c\u7edf\u8ba1\u5206\u6790\u7b49\u3002P [&hellip;]","protected":false},"author":3,"featured_media":303905,"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\/303883"}],"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=303883"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/303883\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/303905"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=303883"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=303883"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=303883"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}