{"id":112,"date":"2026-08-06T00:30:42","date_gmt":"2026-08-05T16:30:42","guid":{"rendered":"https:\/\/ltrainyard.icu\/?p=112"},"modified":"2026-08-06T00:45:51","modified_gmt":"2026-08-05T16:45:51","slug":"day-23-pandas%ef%bc%9aseries-%e4%b8%8e-dataframe-%e8%a1%a8%e6%a0%bc%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"https:\/\/ltrainyard.icu\/index.php\/2026\/08\/06\/day-23-pandas%ef%bc%9aseries-%e4%b8%8e-dataframe-%e8%a1%a8%e6%a0%bc%e5%88%86%e6%9e%90\/","title":{"rendered":"| Day 23 | Pandas\uff1aSeries \u4e0e DataFrame \u8868\u683c\u5206\u6790 |"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">1 Series \u2014\u2014 \u4e00\u5217\u300c\u5e26\u540d\u724c\u300d\u7684\u6570\u636e<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Series<\/strong>\uff08\u5e8f\u5217\uff09\u662f Pandas \u7684\u4e00\u7ef4\u6570\u636e\u7ed3\u6784\uff1a\u4e00\u4e32\u503c + \u4e00\u6392\u884c\u6807\u7b7e\uff08index\uff09\uff0c\u50cf\u300c\u4e00\u5217 Excel \u6570\u636e\u300d\u3002\u5b83\u662f DataFrame\uff08\u8868\u683c\uff09\u7684<strong>\u57fa\u672c\u7ec4\u6210\u5355\u4f4d<\/strong>\u2014\u2014\u6bcf\u5217\u90fd\u662f\u4e00\u4e2a Series\u3002\u7406\u89e3 Series \u7684\u300c\u6807\u7b7e\u300d\u548c\u300c\u4f4d\u7f6e\u300d\u4e24\u4e2a\u6982\u5ff5\uff0c\u540e\u9762\u6240\u6709 Pandas \u64cd\u4f5c\u90fd\u5efa\u7acb\u5728\u8fd9\u4e0a\u9762\u3002\u6628\u5929\u5b66\u7684 NumPy \u89e3\u51b3\u4e86\u300c\u6570\u503c\u8ba1\u7b97\u300d\uff0c\u4f46\u771f\u5b9e\u6570\u636e\u901a\u5e38\u662f<strong>\u8868\u683c<\/strong>\uff1a\u6709\u5217\u540d\u3001\u6709\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u3002<strong>Pandas<\/strong> \u5c31\u662f\u4e13\u95e8\u5904\u7406\u8868\u683c\u7684\u5e93\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Series \u7531\u4e24\u90e8\u5206\u7ec4\u6210\uff1a<strong>\u503c\u6570\u7ec4<\/strong>\uff08\u5e95\u5c42\u5c31\u662f NumPy ndarray\uff09\u548c<strong>\u7d22\u5f15\uff08index\uff09<\/strong>\u2014\u2014\u4e00\u7ec4\u6807\u7b7e\u3002\u9ed8\u8ba4\u7d22\u5f15\u662f <code>0, 1, 2...<\/code>\uff08\u53eb RangeIndex\uff09\uff0c\u4e5f\u53ef\u4ee5\u81ea\u5df1\u6307\u5b9a\uff08\u5982 <code>[\"a\", \"b\", \"c\"]<\/code>\uff09\u3002\u53d6\u503c\u6709\u4e24\u79cd\u65b9\u5f0f\uff1a<strong>\u6309\u6807\u7b7e<\/strong>\uff08<code>s[\"b\"]<\/code>\uff0c\u8d70\u7d22\u5f15\u67e5\u627e\uff09\u548c<strong>\u6309\u4f4d\u7f6e<\/strong>\uff08<code>s.iloc[1]<\/code>\uff0c\u6570\u7b2c\u51e0\u4e2a\uff09\u3002\u6ce8\u610f\uff1apandas 3.0 \u91cc\u7528 <code>s[\u6574\u6570]<\/code> \u53ea\u6309\u6807\u7b7e\u67e5\u627e\u2014\u2014\u5982\u679c\u6807\u7b7e\u4e0d\u662f\u6574\u6570\uff08\u5982 <code>\"a\"<\/code>\uff09\uff0c<code>s[1]<\/code> \u4f1a\u62a5 <code>KeyError<\/code>\uff0c\u8001\u7248\u672c\u300c\u81ea\u52a8\u56de\u9000\u4f4d\u7f6e\u53d6\u503c\u300d\u7684\u884c\u4e3a\u5df2\u88ab\u79fb\u9664\u3002**\u6807\u7b7e\u53ef\u4ee5\u4e0d\u662f\u6570\u5b57\uff0c\u6240\u4ee5\u300c\u7b2c\u51e0\u4e2a\u300d\u5fc5\u987b\u663e\u5f0f\u7528 <code>iloc<\/code>**\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Series \u50cf<strong>\u70b9\u540d\u518c\u4e0a\u7684\u4e00\u5217\u5206\u6570<\/strong>\uff1a\u6bcf\u4e2a\u5206\u6570\u65c1\u8fb9\u90fd\u8d34\u7740\u4e00\u4e2a\u59d3\u540d\u6807\u7b7e\u3002\u4f60\u8981\u67e5\u300c\u5f20\u4e09\u7684\u5206\u6570\u300d\u662f<strong>\u6309\u6807\u7b7e\u627e<\/strong>\uff08\u770b\u540d\u5b57\uff09\uff1b\u8981\u300c\u7b2c\u4e09\u4e2a\u540c\u5b66\u662f\u8c01\u300d\u662f<strong>\u6309\u4f4d\u7f6e\u627e<\/strong>\uff08\u6570\u987a\u5e8f\uff09\u3002\u70b9\u540d\u518c\u7684\u987a\u5e8f\uff08\u4f4d\u7f6e\uff09\u548c\u540d\u5b57\uff08\u6807\u7b7e\uff09\u662f\u4e24\u5957\u7cfb\u7edf\uff0c\u6df7\u7740\u7528\u5c31\u4f1a\u627e\u9519\u4eba\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>\u521b\u5efa Series + \u6309\u6807\u7b7e\u53d6 + \u6309\u4f4d\u7f6e\u53d6<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import pandas as pd\n\ns = pd.Series(&#91;10, 20, 30], index=&#91;\"a\", \"b\", \"c\"])\nprint(s)\nprint(\"\u53d6 b:\", s&#91;\"b\"])        # \u6309\u6807\u7b7e\u53d6\u503c\nprint(\"\u7b2c 2 \u4e2a:\", s.iloc&#91;1])  # \u6309\u4f4d\u7f6e\u53d6\u503c\uff08iloc = integer location\uff09\nprint(\"\u5e73\u5747\u503c:\", s.mean())\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>a    10\nb    20\nc    30\ndtype: int64\n\u53d6 b: 20\n\u7b2c 2 \u4e2a: 20\n\u5e73\u5747\u503c: 20.0\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>pd.Series([10, 20, 30], index=[\"a\", \"b\", \"c\"])<\/code> \u521b\u5efa\u300c\u503c + \u6807\u7b7e\u300d\uff1b\u6253\u5370\u65f6<strong>\u5de6\u8fb9\u662f\u6807\u7b7e\u3001\u53f3\u8fb9\u662f\u503c<\/strong>\uff1b<code>s[\"b\"]<\/code> \u6309\u6807\u7b7e\u53d6 20\uff1b<code>s.iloc[1]<\/code> \u6309\u4f4d\u7f6e\u53d6\u7b2c 2 \u4e2a\uff1b<code>mean()<\/code> \u7b97\u5e73\u5747\u503c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2 <strong>\u6807\u7b7e\u4e5f\u53ef\u4ee5\u662f\u4eba\u540d\uff0c\u652f\u6301\u5e03\u5c14\u7b5b\u9009<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>scores = pd.Series({\"\u5f20\u4e09\": 90, \"\u674e\u56db\": 85, \"\u738b\u4e94\": 60})\nprint(scores&#91;scores &gt;= 85])   # \u5e03\u5c14\u7b5b\u9009\uff1a\u53ea\u770b &gt;=85 \u7684\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u5f20\u4e09    90\n\u674e\u56db    85\ndtype: int64\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7528\u5b57\u5178\u521b\u5efa Series \u65f6\uff0c<strong>\u952e\u6210\u4e3a\u6807\u7b7e\u3001\u503c\u6210\u4e3a\u6570\u636e<\/strong>\uff1b<code>scores &gt;= 85<\/code> \u9010\u5143\u7d20\u6bd4\u8f83\u751f\u6210\u5e03\u5c14\u5e8f\u5217\uff0c\u653e\u8fdb <code>scores[...]<\/code> \u53ea\u4fdd\u7559\u6ee1\u8db3\u6761\u4ef6\u7684\u2014\u2014\u548c NumPy \u5e03\u5c14\u7d22\u5f15\u662f\u540c\u4e00\u4e2a\u601d\u8def\uff0c\u4f46\u7ed3\u679c\u8fd8\u5e26\u7740\u540d\u5b57\u6807\u7b7e\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u6807\u7b7e\u662f <code>\"a\",\"b\",\"c\"<\/code> \u5374\u5199 <code>s[1]<\/code> \u2192 \u95ee\u9898\uff1apandas 3.0 \u8d77\u6574\u6570\u4e0b\u6807\u53ea\u6309\u6807\u7b7e\u67e5\u627e\uff0c\u62a5 <code>KeyError: 1<\/code> \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u6309\u4f4d\u7f6e\u53d6\u7528 <code>s.iloc[1]<\/code>\uff0c\u6309\u6807\u7b7e\u53d6\u7528 <code>s[\"b\"]<\/code>\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>pd.Series([1, 2, 3], index=[\"a\", \"b\", \"c\", \"d\"])<\/code> \u2192 \u95ee\u9898\uff1a\u503c 3 \u4e2a\u3001\u6807\u7b7e 4 \u4e2a\uff0c\u957f\u5ea6\u4e0d\u4e00\u81f4\u62a5 <code>ValueError<\/code> \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u4fdd\u8bc1\u503c\u4e2a\u6570 = \u6807\u7b7e\u4e2a\u6570\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u60f3\u7ed9 Series \u8d77\u300c\u5217\u540d\u300d\u5374\u7528 <code>s[\"\u5217\u540d\"]<\/code> \u521b\u5efa \u2192 \u95ee\u9898\uff1a\u5b57\u5178\u952e\u662f<strong>\u6807\u7b7e<\/strong>\u4e0d\u662f\u5217\u540d\uff0c\u53d6\u4e0d\u5230\u4f1a <code>KeyError<\/code> \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u660e\u786e\u6982\u5ff5\uff1aSeries \u53ea\u6709 index\uff08\u6807\u7b7e\uff09\uff0c\u6ca1\u6709\u5217\u540d\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1aSeries \u4e00\u5217\u5e26\u540d\u724c\uff0c\u6807\u7b7e\u4f4d\u7f6e\u4e24\u5957\u724c\uff1b\u6309\u540d\u7528\u65b9\u62ec\u53f7\uff0c\u6309\u4f4d\u7528 iloc\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2 DataFrame \u2014\u2014 \u4e00\u5f20\u300c\u4f1a\u8ba1\u7b97\u7684 Excel \u8868\u300d<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>DataFrame<\/strong>\uff08\u6570\u636e\u6846\uff09\u662f Pandas \u7684\u4e8c\u7ef4\u8868\u683c\u7ed3\u6784\uff1a<strong>\u591a\u5217\u6570\u636e\uff0c\u6bcf\u5217\u4e00\u4e2a Series\uff0c\u5171\u7528\u4e00\u5957\u884c\u6807\u7b7e<\/strong>\u3002\u5b83\u662f\u6570\u636e\u5206\u6790\u7684\u4e3b\u6218\u573a\u2014\u2014\u8bfb\u6587\u4ef6\u3001\u7b5b\u9009\u3001\u5206\u7ec4\u3001\u7edf\u8ba1\u5168\u5728 DataFrame \u4e0a\u8fdb\u884c\u3002\u7406\u89e3\u300c\u884c\u662f\u8bb0\u5f55\u3001\u5217\u662f\u5b57\u6bb5\u300d\uff0c\u5c31\u7406\u89e3\u4e86\u6570\u636e\u5206\u6790\u7684\u901a\u7528\u89c6\u89d2\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">DataFrame \u662f\u300c<strong>Series \u7684\u5b57\u5178<\/strong>\u300d\uff1a\u5217\u540d \u2192 Series\u3002\u7528\u5b57\u5178\u521b\u5efa\u65f6\uff0c<strong>\u952e\u662f\u5217\u540d\u3001\u503c\u662f\u6574\u5217\u6570\u636e<\/strong>\uff0c\u6240\u6709\u5217\u81ea\u52a8\u6309\u884c\u5bf9\u9f50\u3002<code>df[\"\u5217\u540d\"]<\/code> \u53d6\u4e00\u5217\uff08\u5f97\u5230 Series\uff09\uff1b<code>df[[\"\u52171\", \"\u52172\"]]<\/code> \u53d6\u591a\u5217\uff08\u53cc\u4e2d\u62ec\u53f7\uff0c\u5f97\u5230 DataFrame\uff09\uff1b<code>df.loc[\u884c\u6807\u7b7e]<\/code> \u6309\u884c\u6807\u7b7e\u53d6\u884c\u3001<code>df.iloc[\u884c\u53f7]<\/code> \u6309\u4f4d\u7f6e\u53d6\u884c\u3001<code>df.loc[\u884c, \u5217]<\/code> \u53d6\u5355\u4e2a\u683c\u5b50\u3002<code>df.columns<\/code> \u8fd4\u56de\u5217\u540d\u5217\u8868\u3001<code>df.index<\/code> \u8fd4\u56de\u884c\u6807\u7b7e\u3002<strong>\u884c\u548c\u5217\u662f\u4e24\u5957\u5750\u6807\uff0c<code>loc<\/code> \u6309\u540d\u5b57\u3001<code>iloc<\/code> \u6309\u7f16\u53f7<\/strong>\uff0c\u6df7\u7528\u4f1a\u53d6\u9519\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">DataFrame \u50cf<strong>\u73ed\u7ea7\u6210\u7ee9\u5355<\/strong>\uff1a\u6bcf\u4e00\u884c\u662f\u4e00\u4e2a\u5b66\u751f\uff08\u8bb0\u5f55\uff09\uff0c\u6bcf\u4e00\u5217\u662f\u4e00\u95e8\u8bfe\uff08\u5b57\u6bb5\uff09\uff0c\u8868\u5934\u662f\u5217\u540d\u3001\u6700\u5de6\u5217\u662f\u5b66\u53f7\uff08\u884c\u6807\u7b7e\uff09\u3002\u300c\u67e5\u7b2c 3 \u4e2a\u5b66\u751f\u7684\u6570\u5b66\u5206\u300d\u8981\u4e24\u5957\u5750\u6807\uff1a\u7b2c\u51e0\u884c\uff08\u4f4d\u7f6e\uff09+ \u54ea\u4e00\u5217\uff08\u540d\u5b57\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>\u5b57\u5178\u521b\u5efa DataFrame + \u53d6\u4e00\u5217\/\u591a\u5217<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import pandas as pd\n\ndf = pd.DataFrame({\n    \"\u59d3\u540d\": &#91;\"\u5f20\u4e09\", \"\u674e\u56db\", \"\u738b\u4e94\"],\n    \"\u5206\u6570\": &#91;90, 85, 95],\n    \"\u57ce\u5e02\": &#91;\"\u5317\u4eac\", \"\u4e0a\u6d77\", \"\u5e7f\u5dde\"],\n})\nprint(df)\nprint(\"---\")\nprint(df&#91;\"\u59d3\u540d\"])          # \u4e00\u5217 \u2192 Series\nprint(df&#91;&#91;\"\u59d3\u540d\", \"\u5206\u6570\"]])  # \u591a\u5217 \u2192 DataFrame\uff08\u53cc\u4e2d\u62ec\u53f7\uff09\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>   \u59d3\u540d  \u5206\u6570  \u57ce\u5e02\n0  \u5f20\u4e09  90  \u5317\u4eac\n1  \u674e\u56db  85  \u4e0a\u6d77\n2  \u738b\u4e94  95  \u5e7f\u5dde\n---\n0    \u5f20\u4e09\n1    \u674e\u56db\n2    \u738b\u4e94\nName: \u59d3\u540d, dtype: str\n   \u59d3\u540d  \u5206\u6570\n0  \u5f20\u4e09  90\n1  \u674e\u56db  85\n2  \u738b\u4e94  95\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b57\u5178\u7684\u952e\u6309\u987a\u5e8f\u6210\u4e3a\u5217\u540d\uff0c\u503c\u6309\u987a\u5e8f\u6210\u4e3a\u6bcf\u5217\u6570\u636e\uff1b<code>df[\"\u59d3\u540d\"]<\/code> \u8fd4\u56de Series\uff1b<code>df[[\"\u59d3\u540d\", \"\u5206\u6570\"]]<\/code> \u5fc5\u987b<strong>\u53cc\u4e2d\u62ec\u53f7<\/strong>\u624d\u8868\u793a\u300c\u53d6\u591a\u5217\u300d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2 <strong>loc \u6309\u6807\u7b7e\u53d6\u884c\u3001iloc \u6309\u4f4d\u7f6e\u53d6\u884c\u3001loc \u53d6\u5355\u4e2a\u683c\u5b50<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>df = pd.DataFrame({\"\u59d3\u540d\": &#91;\"\u5f20\u4e09\", \"\u674e\u56db\", \"\u738b\u4e94\"], \"\u5206\u6570\": &#91;90, 85, 95]})\nprint(df.loc&#91;1])           # \u6309\u884c\u6807\u7b7e\u53d6\u7b2c 2 \u884c\nprint(df.iloc&#91;0])          # \u6309\u4f4d\u7f6e\u53d6\u7b2c 1 \u884c\nprint(df.loc&#91;0, \"\u5206\u6570\"])   # \u7b2c 1 \u884c\u3001\u5206\u6570\u5217 \u2192 \u5355\u4e2a\u503c\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u59d3\u540d    \u674e\u56db\n\u5206\u6570    85\nName: 1, dtype: object\n\u59d3\u540d    \u5f20\u4e09\n\u5206\u6570    90\nName: 0, dtype: object\n90\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>df.loc[1]<\/code> \u6309<strong>\u884c\u6807\u7b7e<\/strong>\u53d6\u884c\uff0c\u8fd4\u56de\u4e00\u4e2a\u300c\u7ad6\u7740\u7684 Series\u300d\uff1b<code>df.iloc[0]<\/code> \u6309<strong>\u4f4d\u7f6e<\/strong>\u53d6\u7b2c 1 \u884c\uff1b<code>df.loc[0, \"\u5206\u6570\"]<\/code> \u9017\u53f7\u5206\u9694\u300c\u884c, \u5217\u300d\u76f4\u63a5\u53d6\u4e00\u4e2a\u683c\u5b50\u2014\u2014**\u884c\u6807\u7b7e\u548c\u4f4d\u7f6e\u5728\u9ed8\u8ba4\u7d22\u5f15\u4e0b\u6070\u597d\u4e00\u81f4\uff0c\u4f46\u4e00\u65e6\u884c\u6807\u7b7e\u53d8\u6210\u65e5\u671f\/\u4eba\u540d\uff0c\u5fc5\u987b\u7528 <code>loc<\/code>**\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>df[\"\u59d3\u540d\", \"\u5206\u6570\"]<\/code> \u60f3\u53d6\u4e24\u5217 \u2192 \u95ee\u9898\uff1a\u9017\u53f7\u662f\u300c\u884c, \u5217\u300d\u8bed\u6cd5\uff0c\u62a5 <code>KeyError<\/code> \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u53d6\u591a\u5217\u5fc5\u987b\u53cc\u4e2d\u62ec\u53f7\uff1a<code>df[[\"\u59d3\u540d\", \"\u5206\u6570\"]]<\/code>\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u884c\u6807\u7b7e\u662f\u65e5\u671f\u5374\u7528 <code>df.iloc[\"2026-08-01\"]<\/code> \u2192 \u95ee\u9898\uff1a<code>iloc<\/code> \u53ea\u8ba4\u4f4d\u7f6e\u7f16\u53f7\uff0c\u4f20\u6807\u7b7e\u62a5\u9519 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u6309\u6807\u7b7e\u7528 <code>df.loc[\"2026-08-01\"]<\/code>\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>df[\"\u4e0d\u5b58\u5728\u7684\u5217\"]<\/code> \u2192 \u95ee\u9898\uff1a\u5217\u540d\u62fc\u9519\uff0c\u62a5 <code>KeyError<\/code> \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u5148 <code>print(df.columns)<\/code> \u770b\u771f\u5b9e\u5217\u540d\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1aDataFrame \u662f\u6210\u7ee9\u5355\uff1a\u884c\u662f\u8bb0\u5f55\u5217\u662f\u5b57\u6bb5\uff1b\u53d6\u4e00\u5217\u5355\u62ec\u53f7\uff0c\u53d6\u591a\u5217\u53cc\u62ec\u53f7\uff1bloc \u6309\u540d iloc \u6309\u53f7\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3 read_csv \u2014\u2014 \u4e00\u884c\u628a\u6587\u4ef6\u53d8\u6210\u8868\u683c<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>CSV<\/strong>\uff08Comma-Separated Values\uff0c\u9017\u53f7\u5206\u9694\u503c\uff09\u662f\u6570\u636e\u4ea4\u6362\u6700\u5e38\u89c1\u7684\u683c\u5f0f\uff1a\u7eaf\u6587\u672c\u3001\u4e00\u884c\u4e00\u6761\u8bb0\u5f55\u3001\u9017\u53f7\u5206\u5217\uff0cExcel \u5bfc\u51fa\u7684\u6570\u636e\u3001\u7f51\u4e0a\u516c\u5f00\u6570\u636e\u96c6\u57fa\u672c\u90fd\u662f\u5b83\u3002<code>pd.read_csv(\"\u6587\u4ef6\")<\/code> \u4e00\u884c\u8bfb\u6210 DataFrame\u2014\u2014\u8fd9\u662f\u300c\u771f\u5b9e\u6570\u636e\u5206\u6790\u300d\u7684\u5165\u53e3\uff1a\u6570\u636e\u51e0\u4e4e\u90fd\u4ece\u6587\u4ef6\u6765\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>read_csv<\/code> \u4f1a\u81ea\u52a8\u5b8c\u6210\u4e09\u4ef6\u4e8b\uff1a<strong>\u7b2c\u4e00\u884c\u8bc6\u522b\u4e3a\u5217\u540d<\/strong>\uff08header\uff09\u3001<strong>\u6309\u9017\u53f7\u5207\u5206\u6bcf\u4e00\u884c<\/strong>\u3001<strong>\u81ea\u52a8\u63a8\u65ad\u6bcf\u5217\u7c7b\u578b<\/strong>\uff08\u6570\u5b57\u5217 \u2192 <code>int64<\/code> \/ <code>float64<\/code>\uff0c\u6587\u672c\u5217 \u2192 <code>str<\/code>\uff09\u3002\u6ce8\u610f pandas 3.0 \u4e2d\u6587\u672c\u5217 dtype \u663e\u793a\u4e3a <code>str<\/code>\uff08\u8001\u7248\u672c\u53eb <code>object<\/code>\uff09\uff0c\u542b\u4e49\u4e00\u6837\uff1a\u8fd9\u5217\u662f\u6587\u672c\u3002\u4e2d\u6587 CSV \u5fc5\u987b\u6ce8\u610f<strong>\u7f16\u7801<\/strong>\uff1a\u5199\u6587\u4ef6\u7528 <code>utf-8<\/code>\uff0c\u8bfb\u6587\u4ef6\u4e5f\u8981\u6307\u5b9a <code>encoding=\"utf-8\"<\/code>\uff0c\u5426\u5219\u53ef\u80fd\u4e71\u7801\u6216\u62a5 <code>UnicodeDecodeError<\/code>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">CSV \u50cf<strong>\u8d85\u5e02\u8fdb\u8d27\u5355\u7684\u7eaf\u6587\u672c\u7248<\/strong>\uff1a\u4e00\u884c\u4e00\u4e2a\u5546\u54c1\uff0c\u9017\u53f7\u662f\u300c\u5206\u680f\u300d\u7684\u5206\u9694\u7ebf\u3002<code>read_csv<\/code> \u50cf<strong>\u626b\u7801\u67aa<\/strong>\uff1a\u5bf9\u7740\u6574\u5f20\u5355\u5b50\u626b\u4e00\u904d\uff0c\u81ea\u52a8\u8ba4\u51fa\u300c\u7b2c\u4e00\u884c\u662f\u8868\u5934\u3001\u540e\u9762\u662f\u6570\u636e\u3001\u6570\u5b57\u5f52\u6570\u5b57\u3001\u6587\u5b57\u5f52\u6587\u5b57\u300d\uff0c\u88c5\u8fdb\u4e00\u4e2a\u5e26\u683c\u5b50\u7684\u8868\u683c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>\u5199\u4e00\u4e2a CSV \u518d\u8bfb\u8fdb\u6765\uff08\u79bb\u7ebf\u6f14\u793a\uff09<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import pandas as pd\n\nwith open(\"city.csv\", \"w\", encoding=\"utf-8\") as f:\n    f.write(\"\u57ce\u5e02,\u4eba\u53e3(\u4e07),GDP(\u4ebf)\\n\")\n    f.write(\"\u5317\u4eac,2189,40000\\n\")\n    f.write(\"\u4e0a\u6d77,2487,45000\\n\")\n    f.write(\"\u5e7f\u5dde,1874,28000\\n\")\n\ndf = pd.read_csv(\"city.csv\", encoding=\"utf-8\")\nprint(df)\nprint(\"\u5217\u540d:\", list(df.columns))\nprint(\"\u5404\u5217\u7c7b\u578b:\")\nprint(df.dtypes)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>   \u57ce\u5e02  \u4eba\u53e3(\u4e07)  GDP(\u4ebf)\n0  \u5317\u4eac   2189   40000\n1  \u4e0a\u6d77   2487   45000\n2  \u5e7f\u5dde   1874   28000\n\u5217\u540d: &#91;'\u57ce\u5e02', '\u4eba\u53e3(\u4e07)', 'GDP(\u4ebf)']\n\u5404\u5217\u7c7b\u578b:\n\u57ce\u5e02          str\n\u4eba\u53e3(\u4e07)     int64\nGDP(\u4ebf)    int64\ndtype: object\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>pd.read_csv(\"city.csv\", encoding=\"utf-8\")<\/code> \u8bfb\u5165\u540e<strong>\u7b2c\u4e00\u884c\u81ea\u52a8\u6210\u4e3a\u5217\u540d<\/strong>\uff0c\u4e2d\u6587\u5217\u540d\u4e5f\u6b63\u5e38\uff1b<code>df.columns<\/code> \u5217\u51fa\u5217\u540d\u3001<code>df.dtypes<\/code> \u770b\u6bcf\u5217\u7c7b\u578b\u2014\u2014\u6570\u5b57\u5217\u81ea\u52a8\u8bc6\u522b\u6210 <code>int64<\/code>\uff0c\u6587\u672c\u5217\u662f <code>str<\/code>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>pd.read_csv(\"\u6587\u4ef6.csv\")<\/code> \u8bfb\u4e2d\u6587\u6587\u4ef6\u4e71\u7801 \u2192 \u95ee\u9898\uff1a\u7cfb\u7edf\u9ed8\u8ba4\u7f16\u7801\u4e0d\u662f utf-8\uff0c\u4e2d\u6587\u89e3\u6790\u5931\u8d25 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a<code>pd.read_csv(\"\u6587\u4ef6.csv\", encoding=\"utf-8\")<\/code>\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u5199\u6587\u4ef6\u7528 <code>encoding=\"gbk\"<\/code>\u3001\u8bfb\u6587\u4ef6\u7528 <code>encoding=\"utf-8\"<\/code> \u2192 \u95ee\u9898\uff1a\u8bfb\u5199\u7f16\u7801\u4e0d\u4e00\u81f4\uff0c\u8bfb\u51fa\u6765\u662f\u4e71\u7801 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u5199\u548c\u8bfb\u90fd\u7528 <code>encoding=\"utf-8\"<\/code>\uff0c\u4fdd\u6301\u7edf\u4e00\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u6587\u4ef6\u7b2c\u4e00\u884c\u4e0d\u662f\u8868\u5934\u5374\u76f4\u63a5\u8bfb \u2192 \u95ee\u9898\uff1a\u6570\u636e\u884c\u88ab\u5f53\u6210\u5217\u540d\uff0c<code>df[\"\u52171\"]<\/code> \u5168\u9519 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u6ca1\u6709\u8868\u5934\u65f6 <code>pd.read_csv(\"\u6587\u4ef6\", header=None)<\/code>\uff0c\u518d\u624b\u52a8 <code>df.columns = [...]<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1aCSV \u9017\u53f7\u5206\u680f\uff0cread_csv \u81ea\u52a8\u5206\uff1b\u7b2c\u4e00\u884c\u662f\u8868\u5934\uff0c\u4e2d\u6587\u8bb0\u5f97 utf-8\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4 head \/ info \/ describe \u2014\u2014 \u65b0\u6570\u636e\u7684\u300c\u4e09\u5206\u949f\u4f53\u68c0\u300d<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u62ff\u5230\u4efb\u4f55\u964c\u751f\u8868\u683c\uff0c\u7b2c\u4e00\u6b65\u4e0d\u662f\u5199\u5206\u6790\u4ee3\u7801\uff0c\u800c\u662f<strong>\u5148\u4f53\u68c0<\/strong>\uff1a\u6570\u636e\u957f\u4ec0\u4e48\u6837\u3001\u6709\u591a\u5c11\u884c\u3001\u6bcf\u5217\u662f\u4ec0\u4e48\u7c7b\u578b\u3001\u6709\u6ca1\u6709\u7f3a\u503c\u3001\u6570\u503c\u5206\u5e03\u5982\u4f55\u3002<code>head<\/code>\uff08\u770b\u524d\u51e0\u884c\uff09\u3001<code>info<\/code>\uff08\u7ed3\u6784\u4f53\u68c0\uff09\u3001<code>describe<\/code>\uff08\u6570\u503c\u7edf\u8ba1\uff09\u4e09\u4ef6\u5957\u5c31\u662f\u4f53\u68c0\u4eea\u2014\u2014<strong>\u4e0d\u4f53\u68c0\u5c31\u5206\u6790\uff0c\u7b49\u4e8e\u4e0d\u770b\u8bf4\u660e\u4e66\u5c31\u5f00\u8f66<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>head(n)<\/code>\uff1a\u53d6<strong>\u524d n \u884c<\/strong>\uff08\u9ed8\u8ba4 5\uff09\uff0c<code>tail(n)<\/code> \u53d6\u540e n \u884c\u2014\u2014\u5148\u770b\u300c\u957f\u4ec0\u4e48\u6837\u300d<\/li>\n\n\n\n<li><code>info()<\/code>\uff1a\u6253\u5370 <strong>RangeIndex\uff08\u884c\u6570\u8303\u56f4\uff09\u3001\u6bcf\u5217\u975e\u7a7a\u6570\u91cf\u3001dtype \u7c7b\u578b<\/strong>\u2014\u2014\u77e5\u9053\u300c\u6bcf\u5217\u662f\u4ec0\u4e48\u3001\u7f3a\u4e0d\u7f3a\u503c\u300d<\/li>\n\n\n\n<li><code>describe()<\/code>\uff1a\u53ea\u7edf\u8ba1<strong>\u6570\u503c\u5217<\/strong>\uff0c\u7ed9\u51fa <code>count<\/code>\uff08\u6570\u91cf\uff09\u3001<code>mean<\/code>\uff08\u5e73\u5747\uff09\u3001<code>std<\/code>\uff08\u6807\u51c6\u5dee\uff09\u3001<code>min<\/code>\/<code>max<\/code>\uff08\u6700\u5927\u6700\u5c0f\uff09\u3001<code>25%<\/code>\/<code>50%<\/code>\/<code>75%<\/code>\uff08\u56db\u5206\u4f4d\u6570\uff09\u3002<strong>pandas 3.0 \u7684\u6253\u5370\u4f18\u5316<\/strong>\uff1a\u67d0\u5217\u6240\u6709\u7edf\u8ba1\u503c\u80fd\u7cbe\u786e\u8868\u793a\u65f6\u7528\u6700\u77ed\u683c\u5f0f\uff08\u5982 <code>85.0<\/code>\uff09\uff0c\u542b\u65e0\u9650\u5c0f\u6570\u65f6\u7528 6 \u4f4d\u5c0f\u6570\uff08\u5982 <code>84.333333<\/code>\uff09\u2014\u2014\u8fd9\u662f\u65b0\u7248\u663e\u793a\u884c\u4e3a\uff0c\u4e0d\u662f\u7cbe\u5ea6\u95ee\u9898<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f53\u68c0\u4e09\u4ef6\u5957\u50cf<strong>\u5165\u804c\u68c0\u67e5<\/strong>\uff1ahead \u662f\u300c\u770b\u7167\u7247\u8ba4\u4eba\u300d\uff08\u6b63\u9762\u7167\u3001\u4fa7\u9762\u7167\uff09\uff0cinfo \u662f\u300c\u8eab\u9ad8\u4f53\u91cd\u8840\u538b\u300d\uff08\u57fa\u7840\u6307\u6807\uff09\uff0cdescribe \u662f\u300c\u5404\u9879\u5316\u9a8c\u5355\u300d\uff08\u8be6\u7ec6\u6570\u503c\u8303\u56f4\uff09\u3002\u4e09\u6837\u770b\u5b8c\uff0c\u4f60\u5bf9\u8fd9\u4f4d\u300c\u65b0\u5458\u5de5\u300d\uff08\u6570\u636e\uff09\u5c31\u6709\u6570\u4e86\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>head \/ tail \u770b\u5934\u5c3e<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>df = pd.read_csv(\"scores3.csv\")\nprint(df.tail(2))          # \u770b\u540e 2 \u884c\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>   \u59d3\u540d  \u8bed\u6587  \u6570\u5b66  \u82f1\u8bed\n2  \u738b\u4e94  90  88  92\n3  \u8d75\u516d  95  98  96\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>tail(2)<\/code> \u53d6\u6700\u540e 2 \u884c\u2014\u2014\u914d\u5408 <code>head()<\/code> \u4e00\u524d\u4e00\u540e\uff0c\u5feb\u901f\u786e\u8ba4\u300c\u6570\u636e\u6709\u6ca1\u6709\u5012\u5e8f\u3001\u5c3e\u90e8\u6709\u6ca1\u6709\u5f02\u5e38\u884c\u300d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2 <strong>info \u770b\u7ed3\u6784 + describe \u770b\u7edf\u8ba1<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>print(\"=== \u57fa\u672c\u4fe1\u606f ===\")\ndf.info()\nprint(\"=== \u6570\u503c\u7edf\u8ba1 ===\")\nprint(df.describe())\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>=== \u57fa\u672c\u4fe1\u606f ===\n&lt;class 'pandas.DataFrame'&gt;\nRangeIndex: 4 entries, 0 to 3\nData columns (total 4 columns):\n #   Column  Non-Null Count  Dtype\n---  ------  --------------  -----\n 0   \u59d3\u540d      4 non-null      str\n 1   \u8bed\u6587      4 non-null      int64\n 2   \u6570\u5b66      4 non-null      int64\n 3   \u82f1\u8bed      4 non-null      int64\ndtypes: int64(3), str(1)\nmemory usage: 260.0 bytes\n=== \u6570\u503c\u7edf\u8ba1 ===\n              \u8bed\u6587         \u6570\u5b66         \u82f1\u8bed\ncount   4.000000   4.000000   4.000000\nmean   87.000000  89.500000  87.750000\nstd     8.524475   7.549834   7.932003\nmin    75.000000  80.000000  78.000000\n25%    84.750000  86.000000  83.250000\n50%    89.000000  90.000000  88.500000\n75%    91.250000  93.500000  93.000000\nmax    95.000000  98.000000  96.000000\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>info()<\/code> \u663e\u793a\u603b\u884c\u6570\uff084 entries\uff09\u3001\u6bcf\u5217<strong>\u975e\u7a7a\u6570\u91cf<\/strong>\uff08\u90fd\u662f 4 non-null\uff0c\u8bf4\u660e\u6ca1\u7f3a\u503c\uff09\u548c\u7c7b\u578b\uff1b<code>describe()<\/code> \u53ea\u7edf\u8ba1\u6570\u503c\u5217\uff1a\u8bed\u6587 25% \u5206\u4f4d 84.75 \u8868\u793a\u300c25% \u7684\u4eba\u4f4e\u4e8e 84.75\u300d\uff0c<code>50%<\/code> \u662f\u4e2d\u4f4d\u6570\u3002\u6ce8\u610f\u8fd9\u4e09\u5217\u90fd\u663e\u793a\u6210 6 \u4f4d\u5c0f\u6570\u2014\u2014\u56e0\u4e3a\u6807\u51c6\u5dee\u662f\u65e0\u9650\u5c0f\u6570\uff0c<strong>\u53ea\u8981\u67d0\u5217\u6709\u4efb\u610f\u4e00\u4e2a\u7edf\u8ba1\u503c\u4e0d\u80fd\u7cbe\u786e\u8868\u793a\uff0c\u8be5\u5217\u6240\u6709\u503c\u5c31\u7edf\u4e00\u7528 6 \u4f4d\u5c0f\u6570\u663e\u793a<\/strong>\u3002\u8fd9\u662f pandas 3.0 \u7684\u663e\u793a\u89c4\u5219\uff0c\u4e0d\u662f\u6570\u636e\u7cbe\u5ea6\u95ee\u9898\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>df.head()<\/code> \u540e\u76f4\u63a5\u5206\u6790\u5168\u90e8\u6570\u636e \u2192 \u95ee\u9898\uff1a\u53ea\u770b\u4e86\u524d 5 \u884c\uff0c\u540e\u9762\u7684\u810f\u6570\u636e\u6ca1\u770b\u5230 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u914d\u5408 <code>tail()<\/code>\u3001<code>info()<\/code>\u3001<code>describe()<\/code> \u5168\u9762\u4f53\u68c0\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u8ba4\u4e3a <code>describe<\/code> \u4f1a\u7edf\u8ba1\u6587\u672c\u5217 \u2192 \u95ee\u9898\uff1a<code>describe()<\/code> \u9ed8\u8ba4\u53ea\u7edf\u8ba1\u6570\u503c\u5217\uff0c\u6587\u672c\u5217\u88ab\u5ffd\u7565 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u60f3\u7edf\u8ba1\u6587\u672c\u5217\u7528 <code>df[\"\u5217\"].value_counts()<\/code>\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a\u770b\u5230 <code>85.0<\/code> \u548c <code>85.000000<\/code> \u4ee5\u4e3a\u6570\u636e\u4e0d\u4e00\u81f4 \u2192 \u95ee\u9898\uff1apandas 3.0 \u7684\u6700\u77ed\u7cbe\u786e\u663e\u793a\u4f18\u5316 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u8fd9\u662f\u663e\u793a\u683c\u5f0f\u5dee\u5f02\uff0c\u6570\u636e\u7cbe\u5ea6\u4e00\u81f4\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1a\u65b0\u6570\u636e\u5148\u4f53\u68c0\uff1ahead \u770b\u5934 tail \u770b\u5c3e\uff0cinfo \u67e5\u7ed3\u6784\uff0cdescribe \u770b\u5206\u5e03\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5 groupby \u2014\u2014 \u4e00\u952e\u300c\u5206\u7ec4\u6c47\u603b\u300d<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>groupby<\/strong>\uff08\u5206\u7ec4\uff09\u662f\u6570\u636e\u5206\u6790\u6700\u9ad8\u9891\u7684\u64cd\u4f5c\uff1a\u6309\u90e8\u95e8\u7b97\u5e73\u5747\u5de5\u8d44\u3001\u6309\u5546\u54c1\u7b97\u603b\u9500\u91cf\u3001\u6309\u57ce\u5e02\u7edf\u8ba1\u4eba\u6570\u3002<code>df.groupby(\"\u5217\").\u7edf\u8ba1()<\/code> \u4e00\u884c\u5b8c\u6210\u300c<strong>\u6309\u67d0\u5217\u5206\u7ec4 \u2192 \u5bf9\u6bcf\u7ec4\u505a\u7edf\u8ba1<\/strong>\u300d\uff0c\u662f\u300c\u5206\u7c7b\u6c47\u603b\u300d\u7684\u81ea\u52a8\u5316\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5e95\u5c42\u539f\u7406<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>groupby(\"\u90e8\u95e8\")<\/code> \u5148\u628a\u6570\u636e\u6309\u300c\u90e8\u95e8\u300d\u5217\u7684\u503c\u5206\u6210\u82e5\u5e72\u7ec4\uff08\u5185\u90e8\u662f\u300c\u952e \u2192 \u5b50\u8868\u300d\u7684\u6620\u5c04\uff09\uff0c\u7136\u540e\u5bf9\u6bcf\u7ec4\u6267\u884c\u540e\u7eed\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>df.groupby(\"\u90e8\u95e8\")[\"\u5de5\u8d44\"].mean()<\/code>\uff1a\u5148\u53d6\u6bcf\u7ec4\u7684\u300c\u5de5\u8d44\u300d\u5217\uff0c\u518d\u7b97\u5e73\u5747\u2014\u2014<strong>\u7ed3\u679c\u662f\u4e00\u4e2a Series\uff0c\u5206\u7ec4\u952e\u53d8\u6210\u7d22\u5f15\uff08index\uff09<\/strong><\/li>\n\n\n\n<li><code>.agg([\"mean\", \"sum\", \"max\"])<\/code>\uff1a\u4e00\u6b21\u7b97\u591a\u4e2a\u7edf\u8ba1\u91cf\uff0c\u7ed3\u679c\u5e26\u591a\u5c42\u7d22\u5f15<\/li>\n\n\n\n<li><code>reset_index()<\/code>\uff1a\u628a\u5206\u7ec4\u952e<strong>\u4ece\u7d22\u5f15\u53d8\u56de\u666e\u901a\u5217<\/strong>\uff0c\u5f97\u5230\u300c\u5e72\u51c0\u7684\u8868\u683c\u300d<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u751f\u6d3b\u7c7b\u6bd4<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">groupby \u50cf<strong>\u6559\u52a1\u5904\u6309\u73ed\u7ea7\u5206\u5377\u5b50<\/strong>\uff1a\u5148\u6309\u73ed\u7ea7\u628a\u4e00\u645e\u5377\u5b50\u5206\u6210\u51e0\u6c93\uff08\u5206\u7ec4\uff09\uff0c\u518d\u5bf9\u6bcf\u6c93\u7b97\u5e73\u5747\u5206\uff08\u7edf\u8ba1\uff09\u2014\u2014\u4e0d\u7528\u4f60\u624b\u52a8\u300c\u4e00\u5f20\u5f20\u6311\u51fa\u6765\u518d\u7b97\u300d\u3002<code>reset_index<\/code> \u50cf\u628a\u300c\u6bcf\u6c93\u5377\u5b50\u4e0a\u8d34\u7684\u73ed\u7ea7\u6807\u7b7e\u300d\u6284\u5230\u6210\u7ee9\u8868\u91cc\uff0c\u53d8\u6210\u4e00\u5217\u666e\u901a\u6570\u636e\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6ce8\u610f\u4e8b\u9879\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 <strong>\u5206\u7ec4\u6c42\u5e73\u5747 + \u6c42\u548c + \u8ba1\u6570<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import pandas as pd\n\ndf = pd.DataFrame({\n    \"\u90e8\u95e8\": &#91;\"\u9500\u552e\", \"\u6280\u672f\", \"\u9500\u552e\", \"\u6280\u672f\", \"\u884c\u653f\"],\n    \"\u59d3\u540d\": &#91;\"\u5f20\u4e09\", \"\u674e\u56db\", \"\u738b\u4e94\", \"\u8d75\u516d\", \"\u5b59\u4e03\"],\n    \"\u5de5\u8d44\": &#91;8000, 12000, 9000, 15000, 6000],\n})\nprint(df.groupby(\"\u90e8\u95e8\")&#91;\"\u5de5\u8d44\"].mean())\nprint(df.groupby(\"\u90e8\u95e8\")&#91;\"\u5de5\u8d44\"].sum())\nprint(df.groupby(\"\u90e8\u95e8\")&#91;\"\u59d3\u540d\"].count())\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u90e8\u95e8\n\u6280\u672f    13500.0\n\u884c\u653f     6000.0\n\u9500\u552e     8500.0\nName: \u5de5\u8d44, dtype: float64\n---\n\u90e8\u95e8\n\u6280\u672f    27000\n\u884c\u653f     6000\n\u9500\u552e    17000\nName: \u5de5\u8d44, dtype: int64\n---\n\u90e8\u95e8\n\u6280\u672f    2\n\u884c\u653f    1\n\u9500\u552e    2\nName: \u59d3\u540d, dtype: int64\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>df.groupby(\"\u90e8\u95e8\")<\/code> \u6309\u90e8\u95e8\u5206 3 \u7ec4\uff0c<code>[\"\u5de5\u8d44\"]<\/code> \u9009\u5de5\u8d44\u5217\uff0c<code>.mean()<\/code> \u6bcf\u7ec4\u5e73\u5747\u2014\u2014<strong>\u7ed3\u679c\u91cc\u300c\u90e8\u95e8\u300d\u6210\u4e86\u7d22\u5f15\uff0c\u81ea\u52a8\u6309\u62fc\u97f3\/\u5b57\u6bcd\u987a\u5e8f\u6392<\/strong>\uff1b<code>sum()<\/code> \u6c42\u548c\u3001<code>count()<\/code> \u6570\u6bcf\u7ec4\u4eba\u6570\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2 <strong>agg \u4e00\u6b21\u7b97\u591a\u4e2a\u7edf\u8ba1 + reset_index \u53d8\u56de\u666e\u901a\u5217<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>df = pd.DataFrame({\n    \"\u90e8\u95e8\": &#91;\"\u9500\u552e\", \"\u6280\u672f\", \"\u9500\u552e\"],\n    \"\u5de5\u8d44\": &#91;8000, 12000, 9000],\n})\ng = df.groupby(\"\u90e8\u95e8\")&#91;\"\u5de5\u8d44\"].agg(&#91;\"mean\", \"sum\", \"max\"])\nprint(g)\nprint(\"---\")\nprint(g.reset_index())\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>       mean    sum    max\n\u90e8\u95e8\n\u6280\u672f  12000.0  12000  12000\n\u9500\u552e   8500.0  17000   9000\n---\n   \u90e8\u95e8     mean    sum    max\n0  \u6280\u672f  12000.0  12000  12000\n1  \u9500\u552e   8500.0  17000   9000\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><code>.agg([\"mean\", \"sum\", \"max\"])<\/code> \u4e00\u6b21\u7b97\u4e09\u4e2a\u7edf\u8ba1\u91cf\uff0c\u5217\u540d\u5c31\u662f\u7edf\u8ba1\u540d\uff1b\u7ed3\u679c\u91cc\u300c\u90e8\u95e8\u300d\u662f\u7d22\u5f15\uff08\u6253\u5370\u65f6\u5de6\u8fb9\u7a7a\u4e86\u4e00\u683c\uff09\uff1b<code>reset_index()<\/code> \u628a\u90e8\u95e8<strong>\u53d8\u6210\u666e\u901a\u5217<\/strong>\uff0c\u7d22\u5f15\u6062\u590d\u6210 0, 1\u2014\u2014\u60f3\u7ee7\u7eed\u7528 <code>df[\"\u90e8\u95e8\"]<\/code> \u7b5b\u9009\u6216\u5408\u5e76\u65f6\uff0c\u5148 <code>reset_index()<\/code> \u66f4\u987a\u624b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6613\u9519\u70b9<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>df.groupby(\"\u90e8\u95e8\").mean()<\/code> \u60f3\u7edf\u8ba1\u6240\u6709\u5217 \u2192 \u95ee\u9898\uff1a\u6587\u672c\u5217\uff08\u59d3\u540d\uff09\u4f1a\u88ab\u8df3\u8fc7\uff0c\u53ea\u7edf\u8ba1\u6570\u503c\u5217 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u660e\u786e\u60f3\u7edf\u8ba1\u54ea\u5217\uff1a<code>df.groupby(\"\u90e8\u95e8\")[\"\u5de5\u8d44\"].mean()<\/code>\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1agroupby \u7ed3\u679c\u91cc\u76f4\u63a5 <code>df[\"\u90e8\u95e8\"]<\/code> \u2192 \u95ee\u9898\uff1a\u5206\u7ec4\u952e\u73b0\u5728\u662f<strong>\u7d22\u5f15<\/strong>\u4e0d\u662f\u5217\uff0c\u62a5 <code>KeyError<\/code> \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u5148 <code>reset_index()<\/code> \u518d\u5f53\u666e\u901a\u5217\u7528\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u5199\u6cd5\uff1a<code>df.groupby(\"\u90e8\u95e8\")[\"\u5de5\u8d44\"].mean()<\/code> \u7ed3\u679c\u5f53 DataFrame \u7528 <code>df[\u5217\u540d]<\/code> \u2192 \u95ee\u9898\uff1a\u7ed3\u679c\u662f Series\uff0c\u6ca1\u6709\u5217\u9009\u62e9\u8bed\u6cd5 \u2192 \u6b63\u786e\u5199\u6cd5\uff1a\u60f3\u8981\u8868\u683c\u5f62\u5f0f\u5c31 <code>.agg()<\/code> \u6216 <code>.reset_index()<\/code>\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bb0\u5fc6\u53e3\u8bc0<\/strong>\uff1agroupby \u5206\u5377\u5b50\uff0c\u6bcf\u7ec4\u7b97\u7edf\u8ba1\uff1b\u5206\u7ec4\u952e\u53d8\u7d22\u5f15\uff0creset \u56de\u5217\uff1bagg \u4e00\u6b21\u7b97\u591a\u6837\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6 \u52a8\u624b\u5b9e\u8df5\uff1a\u8bfb\u53d6\u5e76\u5206\u6790 CSV \u6570\u636e<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u505a\u4e00\u4efd\u300c\u9500\u552e\u6570\u636e\u5206\u6790\u300d\uff1a\u5148\u7528\u4ee3\u7801\u751f\u6210\u4e00\u4efd\u5546\u54c1\u9500\u552e CSV\uff0c\u518d\u8bfb\u8fdb\u6765\u5b8c\u6210\u524d\u51e0\u884c\u67e5\u770b\u3001\u57fa\u672c\u4fe1\u606f\u3001\u7edf\u8ba1\u6458\u8981\u3001\u5217\u7b5b\u9009\u3001\u6761\u4ef6\u7b5b\u9009\u3001\u5206\u7ec4\u7edf\u8ba1\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># analyze_sales.py \u2014\u2014 \u8bfb\u53d6\u5e76\u5206\u6790 CSV \u6570\u636e\nimport pandas as pd\n\n# 1. \u51c6\u5907\u4e00\u4efd\u9500\u552e\u6570\u636e CSV\uff08\u6a21\u62df\u6587\u4ef6\uff09\ncsv_text = \"\"\"\u65e5\u671f,\u5546\u54c1,\u7c7b\u522b,\u9500\u91cf,\u5355\u4ef7\n2026-08-01,\u82f9\u679c,\u6c34\u679c,100,8.5\n2026-08-01,\u9999\u8549,\u6c34\u679c,80,4.0\n2026-08-02,\u725b\u5976,\u996e\u54c1,60,12.0\n2026-08-02,\u82f9\u679c,\u6c34\u679c,120,8.5\n2026-08-03,\u9762\u5305,\u98df\u54c1,45,6.5\n2026-08-03,\u725b\u5976,\u996e\u54c1,75,12.0\n\"\"\"\nwith open(\"sales.csv\", \"w\", encoding=\"utf-8\") as f:\n    f.write(csv_text)\n\n# 2. \u8bfb\u53d6\u5e76\u5feb\u901f\u4e86\u89e3\ndf = pd.read_csv(\"sales.csv\")\nprint(\"=== \u524d 3 \u884c ===\")\nprint(df.head(3))\n\nprint(\"\\n=== \u57fa\u672c\u4fe1\u606f ===\")\ndf.info()\n\nprint(\"\\n=== \u7edf\u8ba1\u6458\u8981 ===\")\nprint(df.describe())\n\n# 3. \u5217\u7b5b\u9009\uff1a\u53ea\u770b\u5546\u54c1\u548c\u9500\u91cf\nprint(\"\\n=== \u5546\u54c1\u4e0e\u9500\u91cf\u4e24\u5217 ===\")\nprint(df&#91;&#91;\"\u5546\u54c1\", \"\u9500\u91cf\"]])\n\n# 4. \u6761\u4ef6\u7b5b\u9009\uff1a\u9500\u91cf\u5927\u4e8e 80 \u7684\u8bb0\u5f55\nprint(\"\\n=== \u9500\u91cf\u5927\u4e8e 80 \u7684\u8bb0\u5f55 ===\")\nprint(df&#91;df&#91;\"\u9500\u91cf\"] &gt; 80])\n\n# 5. \u65b0\u589e\u9500\u552e\u989d\u5217\uff0c\u6309\u7c7b\u522b\u6c47\u603b\ndf&#91;\"\u9500\u552e\u989d\"] = df&#91;\"\u9500\u91cf\"] * df&#91;\"\u5355\u4ef7\"]\nprint(\"\\n=== \u5404\u7c7b\u522b\u9500\u552e\u989d\u6c47\u603b ===\")\nprint(df.groupby(\"\u7c7b\u522b\")&#91;\"\u9500\u552e\u989d\"].sum())\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd0\u884c\u7ed3\u679c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>=== \u524d 3 \u884c ===\n           \u65e5\u671f  \u5546\u54c1  \u7c7b\u522b   \u9500\u91cf    \u5355\u4ef7\n0  2026-08-01  \u82f9\u679c  \u6c34\u679c  100   8.5\n1  2026-08-01  \u9999\u8549  \u6c34\u679c   80   4.0\n2  2026-08-02  \u725b\u5976  \u996e\u54c1   60  12.0\n\n=== \u57fa\u672c\u4fe1\u606f ===\n&lt;class 'pandas.DataFrame'&gt;\nRangeIndex: 6 entries, 0 to 5\nData columns (total 5 columns):\n #   Column  Non-Null Count  Dtype\n---  ------  --------------  -----\n 0   \u65e5\u671f      6 non-null      str\n 1   \u5546\u54c1      6 non-null      str\n 2   \u7c7b\u522b      6 non-null      str\n 3   \u9500\u91cf      6 non-null      int64\n 4   \u5355\u4ef7      6 non-null      float64\ndtypes: float64(1), int64(1), str(3)\nmemory usage: 372.0 bytes\n\n=== \u7edf\u8ba1\u6458\u8981 ===\n               \u9500\u91cf         \u5355\u4ef7\ncount    6.000000   6.000000\nmean    80.000000   8.583333\nstd     27.018512   3.121164\nmin     45.000000   4.000000\n25%     63.750000   7.000000\n50%     77.500000   8.500000\n75%     95.000000  11.125000\nmax    120.000000  12.000000\n\n=== \u5546\u54c1\u4e0e\u9500\u91cf\u4e24\u5217 ===\n   \u5546\u54c1   \u9500\u91cf\n0  \u82f9\u679c  100\n1  \u9999\u8549   80\n2  \u725b\u5976   60\n3  \u82f9\u679c  120\n4  \u9762\u5305   45\n5  \u725b\u5976   75\n\n=== \u9500\u91cf\u5927\u4e8e 80 \u7684\u8bb0\u5f55 ===\n           \u65e5\u671f  \u5546\u54c1  \u7c7b\u522b   \u9500\u91cf   \u5355\u4ef7\n0  2026-08-01  \u82f9\u679c  \u6c34\u679c  100  8.5\n3  2026-08-02  \u82f9\u679c  \u6c34\u679c  120  8.5\n\n=== \u5404\u7c7b\u522b\u9500\u552e\u989d\u6c47\u603b ===\n\u7c7b\u522b\n\u6c34\u679c    2190.0\n\u98df\u54c1     292.5\n\u996e\u54c1    1620.0\nName: \u9500\u552e\u989d, dtype: float64\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u7ec3\u4e60\u6a21\u62df\u4e86\u771f\u5b9e\u5de5\u4f5c\u91cc\u7684\u5b8c\u6574\u6d41\u7a0b\uff1a\u62ff\u5230 CSV \u2192 \u4e86\u89e3\u7ed3\u6784 \u2192 \u521d\u6b65\u7edf\u8ba1 \u2192 \u7b5b\u9009\u5173\u6ce8\u7684\u6570\u636e \u2192 \u6309\u7c7b\u522b\u6c47\u603b\u5f97\u51fa\u7ed3\u8bba\u3002\u4ece\u6c47\u603b\u770b\uff0c\u6c34\u679c\u7c7b\u9500\u552e\u989d\u6700\u9ad8\uff082190\uff09\uff0c\u996e\u54c1\u6b21\u4e4b\uff0c\u98df\u54c1\u6700\u4f4e\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u5347\u7ea7\u6311\u6218<\/strong>\uff1a\u7528 <code>df.groupby(\"\u5546\u54c1\")[\"\u9500\u91cf\"].sum()<\/code> \u627e\u51fa\u9500\u91cf\u6700\u9ad8\u7684\u5546\u54c1\uff1b\u7528 <code>df[\"\u65e5\u671f\"]<\/code> \u7edf\u8ba1\u54ea\u5929\u5356\u5f97\u6700\u591a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4eca\u65e5\u603b\u7ed3<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u80fd\u8bf4\u6e05 Series\uff08\u4e00\u5217\u5e26\u6807\u7b7e\uff09\u548c DataFrame\uff08\u591a\u5217\u8868\u683c\uff09\u7684\u533a\u522b\u4e0e\u5173\u7cfb\uff1aDataFrame \u662f\u300cSeries \u7684\u5b57\u5178\u300d\n\u4f1a\u6309\u6807\u7b7e\uff08<code>s[\"b\"]<\/code> \/ <code>loc<\/code>\uff09\u548c\u6309\u4f4d\u7f6e\uff08<code>iloc<\/code>\uff09\u53d6\u503c\uff0c\u77e5\u9053 pandas 3.0 \u91cc <code>s[\u6574\u6570]<\/code> \u53ea\u6309\u6807\u7b7e\u67e5\n\u4f1a\u7528 <code>read_csv<\/code> \u8bfb\u6587\u4ef6\uff08\u8bb0\u5f97 <code>encoding=\"utf-8\"<\/code>\uff09\uff0c\u6587\u672c\u5217\u7c7b\u578b\u663e\u793a\u4e3a <code>str<\/code>\n\u4f1a\u7528 <code>head<\/code> \/ <code>tail<\/code> \/ <code>info<\/code> \/ <code>describe<\/code> \u5feb\u901f\u4e86\u89e3\u6570\u636e\uff0c\u7406\u89e3 describe \u77ed\u683c\u5f0f\u663e\u793a\n\u4f1a\u7528 <code>df[[\"\u5217\"]]<\/code> \u548c <code>df[\u6761\u4ef6]<\/code> \u505a\u5217\u7b5b\u9009\u4e0e\u6761\u4ef6\u7b5b\u9009\uff0c\u591a\u6761\u4ef6\u7528 <code>&amp;<\/code> \/ <code>|<\/code> \u52a0\u62ec\u53f7\n\u4f1a\u7528 <code>groupby<\/code> + \u7edf\u8ba1\u65b9\u6cd5 + <code>agg<\/code> \u505a\u5206\u7ec4\u7edf\u8ba1\uff0c<code>reset_index<\/code> \u628a\u5206\u7ec4\u952e\u53d8\u56de\u5217\n\u9500\u552e\u6570\u636e\u5206\u6790\u811a\u672c\u8fd0\u884c\u6b63\u5e38\uff0c\u5404\u7c7b\u522b\u9500\u552e\u989d\u6c47\u603b\u6b63\u786e<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u62a5\u9519<\/th><th>\u539f\u56e0<\/th><th>\u4fee\u590d<\/th><\/tr><\/thead><tbody><tr><td><code>ModuleNotFoundError: No module named 'pandas'<\/code><\/td><td>\u6ca1\u5b89\u88c5 Pandas<\/td><td><code>pip install pandas<\/code>\uff08\u786e\u8ba4\u5728\u6b63\u786e\u7684\u865a\u62df\u73af\u5883\u91cc\uff09<\/td><\/tr><tr><td><code>UnicodeDecodeError<\/code> \u6216\u4e2d\u6587\u4e71\u7801<\/td><td>\u8bfb\u53d6 CSV \u65f6\u7f16\u7801\u4e0d\u5bf9<\/td><td><code>pd.read_csv(\"\u6587\u4ef6\", encoding=\"utf-8\")<\/code><\/td><\/tr><tr><td><code>ParserError: Error tokenizing data<\/code><\/td><td>CSV \u91cc\u5217\u6570\u4e0d\u4e00\u81f4\uff08\u67d0\u884c\u5c11\u4e2a\u9017\u53f7\uff09<\/td><td>\u7528\u6587\u672c\u7f16\u8f91\u5668\u68c0\u67e5 CSV \u6587\u4ef6\uff0c\u8865\u9f50\u9017\u53f7<\/td><\/tr><tr><td><code>KeyError: '\u5de5\u8d44'<\/code><\/td><td>\u5217\u540d\u5199\u9519\u4e86<\/td><td><code>print(df.columns)<\/code> \u67e5\u770b\u5b9e\u9645\u5217\u540d<\/td><\/tr><tr><td><code>ValueError: The truth value of a Series is ambiguous<\/code><\/td><td>\u6761\u4ef6\u7b5b\u9009\u91cc\u7528\u4e86 <code>and<\/code> \/ <code>or<\/code><\/td><td>\u6362\u6210 <code>&amp;<\/code> \/ <code>|<\/code>\uff0c\u6bcf\u4e2a\u6761\u4ef6\u52a0\u62ec\u53f7<\/td><\/tr><tr><td><code>KeyError: 1<\/code><\/td><td>pandas 3.0 \u8d77 <code>s[\u6574\u6570]<\/code> \u53ea\u6309\u6807\u7b7e\u53d6\u503c\uff0c\u6807\u7b7e\u4e0d\u662f\u6574\u6570\u65f6\u4e0d\u518d\u81ea\u52a8\u56de\u9000\u4f4d\u7f6e<\/td><td>\u6309\u4f4d\u7f6e\u53d6\u7528 <code>s.iloc[1]<\/code>\uff0c\u6309\u6807\u7b7e\u53d6\u7528 <code>s[\"b\"]<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>1 Series \u2014\u2014 \u4e00\u5217\u300c\u5e26\u540d\u724c\u300d\u7684\u6570\u636e \u662f\u4ec0\u4e48\uff1f\u4e3a\u4ec0\u4e48\u5b66\uff1f Series\uff08\u5e8f\u5217\uff09\u662f Pandas \u7684\u4e00\u7ef4 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[16,9],"tags":[17],"class_list":["post-112","post","type-post","status-publish","format-standard","hentry","category-python","category-code-dev","tag-python-day"],"_links":{"self":[{"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/posts\/112","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/comments?post=112"}],"version-history":[{"count":2,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/posts\/112\/revisions"}],"predecessor-version":[{"id":152,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/posts\/112\/revisions\/152"}],"wp:attachment":[{"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/media?parent=112"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/categories?post=112"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ltrainyard.icu\/index.php\/wp-json\/wp\/v2\/tags?post=112"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}