{"id":42,"date":"2019-05-08T22:41:29","date_gmt":"2019-05-08T14:41:29","guid":{"rendered":"https:\/\/kanghaov.com\/?p=42"},"modified":"2024-11-26T15:51:26","modified_gmt":"2024-11-26T07:51:26","slug":"pandas-%e8%af%ad%e6%b3%95%e6%80%bb%e7%bb%93","status":"publish","type":"post","link":"https:\/\/nemo.cool\/42.html","title":{"rendered":"Pandas \u8bed\u6cd5\u603b\u7ed3"},"content":{"rendered":"<h1>\u4ecb\u7ecd<\/h1>\n<p>Pandas \u662f\u57fa\u4e8e NumPy \u7684\u4e00\u79cd\u6570\u636e\u5904\u7406\u5de5\u5177\uff0c\u8be5\u5de5\u5177\u4e3a\u4e86\u89e3\u51b3\u6570\u636e\u5206\u6790\u4efb\u52a1\u800c\u521b\u5efa\u3002Pandas \u7eb3\u5165\u4e86\u5927\u91cf\u5e93\u548c\u4e00\u4e9b\u6807\u51c6\u7684\u6570\u636e\u6a21\u578b\uff0c\u63d0\u4f9b\u4e86\u9ad8\u6548\u5730\u64cd\u4f5c\u5927\u578b\u6570\u636e\u96c6\u6240\u9700\u7684\u51fd\u6570\u548c\u65b9\u6cd5\u3002<\/p>\n<p>Pandas \u7684\u6570\u636e\u7ed3\u6784\uff1aPandas \u4e3b\u8981\u6709 Series\uff08\u4e00\u7ef4\u6570\u7ec4\uff09\uff0cDataFrame\uff08\u4e8c\u7ef4\u6570\u7ec4\uff09\uff0cPanel\uff08\u4e09\u7ef4\u6570\u7ec4\uff09\uff0cPanel4D\uff08\u56db\u7ef4\u6570\u7ec4\uff09\uff0cPanelND\uff08\u66f4\u591a\u7ef4\u6570\u7ec4\uff09\u7b49\u6570\u636e\u7ed3\u6784\u3002\u5176\u4e2d Series \u548c DataFrame \u5e94\u7528\u7684\u6700\u4e3a\u5e7f\u6cdb\u3002<br \/>\n&#8211; Series \u662f\u4e00\u7ef4\u5e26\u6807\u7b7e\u7684\u6570\u7ec4\uff0c\u5b83\u53ef\u4ee5\u5305\u542b\u4efb\u4f55\u6570\u636e\u7c7b\u578b\u3002\u5305\u62ec\u6574\u6570\uff0c\u5b57\u7b26\u4e32\uff0c\u6d6e\u70b9\u6570\uff0cPython \u5bf9\u8c61\u7b49\u3002Series \u53ef\u4ee5\u901a\u8fc7\u6807\u7b7e\u6765\u5b9a\u4f4d\u3002<br \/>\n&#8211; DataFrame \u662f\u4e8c\u7ef4\u7684\u5e26\u6807\u7b7e\u7684\u6570\u636e\u7ed3\u6784\u3002==\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6807\u7b7e\u6765\u5b9a\u4f4d\u6570\u636e\u3002\u8fd9\u662f NumPy \u6240\u6ca1\u6709\u7684\u3002==<\/p>\n<h1>\u77e5\u8bc6\u70b9<\/h1>\n<p>\u672c\u6b21\u5b9e\u9a8c\u6d89\u53ca\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u6709\uff1a<br \/>\n&#8211; \u521b\u5efaSeries<br \/>\n&#8211; Series\u57fa\u672c\u64cd\u4f5c<br \/>\n&#8211; \u521b\u5efaDataFrame<br \/>\n&#8211; DataFrame\u57fa\u672c\u64cd\u4f5c<br \/>\n&#8211; DataFrame\u6587\u4ef6\u64cd\u4f5c<br \/>\n&#8211; Series\uff0cDataFrame\u548c\u591a\u7d22\u5f15<br \/>\n&#8211; \u900f\u89c6\u8868<br \/>\n&#8211; \u6570\u636e\u6e05\u6d17<br \/>\n&#8211; \u6570\u636e\u9884\u5904\u7406<br \/>\n&#8211; \u53ef\u89c6\u5316<\/p>\n<h1>\u57fa\u7840\u90e8\u5206<\/h1>\n<h2>1.\u5bfc\u5165 Pandas \u6a21\u5757<\/h2>\n<h3>1. \u5bfc\u5165 Pandas<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">import pandas as pd\n<\/code><\/pre>\n<h3>2.\u67e5\u770b Pandas \u7248\u672c\u4fe1\u606f<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">print(pd.__version__)\n<\/code><\/pre>\n<h2>2.\u521b\u5efa Series \u6570\u636e\u7c7b\u578b<\/h2>\n<p>==Pandas \u4e2d\uff0cSeries \u53ef\u4ee5\u88ab\u770b\u4f5c\u7531 1 \u5217\u6570\u636e\u7ec4\u6210\u7684\u6570\u636e\u96c6\u3002==<\/p>\n<p>\u521b\u5efa Series \u8bed\u6cd5\uff1a<code>s = pd.Series(data, index=index)<\/code>\uff0c\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u8fdb\u884c\u521b\u5efa\uff0c\u4ee5\u4e0b\u4ecb\u7ecd\u4e86 3 \u4e2a\u5e38\u7528\u65b9\u6cd5\u3002<\/p>\n<h3>2.1 \u4ece\u5217\u8868\u521b\u5efa Series<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">arr = [0, 1, 2, 3, 4]\ns1 = pd.Series(arr)  # \u5982\u679c\u4e0d\u6307\u5b9a\u7d22\u5f15\uff0c\u5219\u9ed8\u8ba4\u4ece 0 \u5f00\u59cb\ns1\n<\/code><\/pre>\n<blockquote><p>\n  \u63d0\u793a\uff1a\u524d\u9762\u7684 <code>0,1,2,3,4<\/code> \u4e3a\u5f53\u524d Series \u7684\u7d22\u5f15\uff0c\u540e\u9762\u7684 <code>0,1,2,3,4<\/code> \u4e3a Series \u7684\u503c\u3002\n<\/p><\/blockquote>\n<h3>2.2 \u4ece Ndarray \u521b\u5efa Series<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">import numpy as np\nn = np.random.randn(5)  # \u521b\u5efa\u4e00\u4e2a\u968f\u673a Ndarray \u6570\u7ec4\n\nindex = ['a', 'b', 'c', 'd', 'e']\ns2 = pd.Series(n, index=index)\ns2\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">a   -1.617725\nb   -0.059218\nc   -1.610177\nd    0.408564\ne   -1.513803\ndtype: float64\n<\/code><\/pre>\n<h3>2.3 \u4ece\u5b57\u5178\u521b\u5efa Series<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">d = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}\ns3 = pd.Series(d)\ns3\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">a    1\nb    2\nc    3\nd    4\ne    5\ndtype: int64\n<\/code><\/pre>\n<h2>3.Series \u57fa\u672c\u64cd\u4f5c<\/h2>\n<h3>3.1 \u4fee\u6539 Series \u7d22\u5f15<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">print(s1)  # \u4ee5 s1 \u4e3a\u4f8b\n\ns1.index = ['A', 'B', 'C', 'D', 'E']  # \u4fee\u6539\u540e\u7684\u7d22\u5f15\ns1\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">0    0\n1    1\n2    2\n3    3\n4    4\ndtype: int64\n\nA    0\nB    1\nC    2\nD    3\nE    4\ndtype: int64\n<\/code><\/pre>\n<h3>3.2 Series \u7eb5\u5411\u62fc\u63a5<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">s4 = s3.append(s1)  # \u5c06 s1 \u62fc\u63a5\u5230 s3\ns4\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">a    1\nb    2\nc    3\nd    4\ne    5\nA    0\nB    1\nC    2\nD    3\nE    4\ndtype: int64\n<\/code><\/pre>\n<h3>3.3 Series \u6309\u6307\u5b9a\u7d22\u5f15\u5220\u9664\u5143\u7d20<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">print(s4)\ns4 = s4.drop('e')  # \u5220\u9664\u7d22\u5f15\u4e3a e \u7684\u503c\ns4\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">a    1\nb    2\nc    3\nd    4\nA    0\nB    1\nC    2\nD    3\nE    4\ndtype: int64\n<\/code><\/pre>\n<h3>3.4 Series \u6309\u6307\u5b9a\u7d22\u5f15\u67e5\u627e\u5143\u7d20<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">s4['B']\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">1\n<\/code><\/pre>\n<h3>3.5 Series \u5207\u7247\u64cd\u4f5c<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">s4[:3]\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">a    1\nb    2\nc    3\ndtype: int64\n<\/code><\/pre>\n<h2>4. Series \u8fd0\u7b97<\/h2>\n<h3>4.1 Series \u52a0\u6cd5\u8fd0\u7b97<\/h3>\n<p>Series \u7684\u52a0\u6cd5\u8fd0\u7b97\u662f\u6309\u7167\u7d22\u5f15\u8ba1\u7b97\uff0c\u5982\u679c\u7d22\u5f15\u4e0d\u540c\u5219\u586b\u5145\u4e3a <code>NaN<\/code>\uff08\u7a7a\u503c\uff09\u3002<\/p>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">s4.add(s3)\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">A    NaN\nB    NaN\nC    NaN\nD    NaN\nE    NaN\na    2.0\nb    4.0\nc    6.0\nd    8.0\ne    NaN\ndtype: float64\n<\/code><\/pre>\n<h3>4.2 Series \u51cf\u6cd5\u8fd0\u7b97<\/h3>\n<p>Series\u7684\u51cf\u6cd5\u8fd0\u7b97\u662f\u6309\u7167\u7d22\u5f15\u5bf9\u5e94\u8ba1\u7b97\uff0c\u5982\u679c\u4e0d\u540c\u5219\u586b\u5145\u4e3a <code>NaN<\/code>\uff08\u7a7a\u503c\uff09\u3002<\/p>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">s4.sub(s3)\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">A    NaN\nB    NaN\nC    NaN\nD    NaN\nE    NaN\na    0.0\nb    0.0\nc    0.0\nd    0.0\ne    NaN\ndtype: float64\n<\/code><\/pre>\n<h3>4.3 Series \u4e58\u6cd5\u8fd0\u7b97<\/h3>\n<p>Series \u7684\u4e58\u6cd5\u8fd0\u7b97\u662f\u6309\u7167\u7d22\u5f15\u5bf9\u5e94\u8ba1\u7b97\uff0c\u5982\u679c\u7d22\u5f15\u4e0d\u540c\u5219\u586b\u5145\u4e3a <code>NaN<\/code>\uff08\u7a7a\u503c\uff09\u3002<\/p>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">s4.mul(s3)\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">A     NaN\nB     NaN\nC     NaN\nD     NaN\nE     NaN\na     1.0\nb     4.0\nc     9.0\nd    16.0\ne     NaN\ndtype: float64\n<\/code><\/pre>\n<h3>4.4 Series \u9664\u6cd5\u8fd0\u7b97<\/h3>\n<p>Series \u7684\u9664\u6cd5\u8fd0\u7b97\u662f\u6309\u7167\u7d22\u5f15\u5bf9\u5e94\u8ba1\u7b97\uff0c\u5982\u679c\u7d22\u5f15\u4e0d\u540c\u5219\u586b\u5145\u4e3a <code>NaN<\/code>\uff08\u7a7a\u503c\uff09\u3002<\/p>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">s4.div(s3)\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">A    NaN\nB    NaN\nC    NaN\nD    NaN\nE    NaN\na    1.0\nb    1.0\nc    1.0\nd    1.0\ne    NaN\ndtype: float64\n<\/code><\/pre>\n<h3>4.5 Series \u6c42\u4e2d\u4f4d\u6570<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">s4.median()\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">2.0\n<\/code><\/pre>\n<h3>4.6 Series \u6c42\u548c<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">s4.sum()\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">20\n<\/code><\/pre>\n<h3>4.7 Series \u6c42\u6700\u5c0f\u503c<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">s4.min()\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">0\n<\/code><\/pre>\n<h2>5.\u521b\u5efa DataFrame \u6570\u636e\u7c7b\u578b<\/h2>\n<p>\u4e0e Sereis \u4e0d\u540c\uff0cDataFrame \u53ef\u4ee5\u5b58\u5728\u591a\u5217\u6570\u636e\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\uff0cDataFrame \u4e5f\u66f4\u52a0\u5e38\u7528\u3002<\/p>\n<h3>5.1 \u901a\u8fc7 NumPy \u6570\u7ec4\u521b\u5efa DataFrame<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">dates = pd.date_range('today', periods=6)  # \u5b9a\u4e49\u65f6\u95f4\u5e8f\u5217\u4f5c\u4e3a index\nnum_arr = np.random.randn(6, 4)  # \u4f20\u5165 numpy \u968f\u673a\u6570\u7ec4\ncolumns = ['A', 'B', 'C', 'D']  # \u5c06\u5217\u8868\u4f5c\u4e3a\u5217\u540d\ndf1 = pd.DataFrame(num_arr, index=dates, columns=columns)\ndf1\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">                                A           B           C           D\n2018-12-18 02:39:40.519323  -0.551914   -1.277574   0.789487    0.153490\n2018-12-19 02:39:40.519323  2.344228    -1.323991   -0.124677   0.296460\n2018-12-20 02:39:40.519323  0.979317    0.434025    -0.060349   -1.838303\n2018-12-21 02:39:40.519323  -0.200960   -1.610445   0.603207    -1.518570\n2018-12-22 02:39:40.519323  -0.955526   -1.444734   -0.729784   -0.708490\n2018-12-23 02:39:40.519323  0.746531    0.619194    -0.856048   -1.421594\n<\/code><\/pre>\n<h3>5.2 \u901a\u8fc7\u5b57\u5178\u6570\u7ec4\u521b\u5efa DataFrame<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">data = {'animal': ['cat', 'cat', 'snake', 'dog', 'dog', 'cat', 'snake', 'cat', 'dog', 'dog'],\n        'age': [2.5, 3, 0.5, np.nan, 5, 2, 4.5, np.nan, 7, 3],\n        'visits': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],\n        'priority': ['yes', 'yes', 'no', 'yes', 'no', 'no', 'no', 'yes', 'no', 'no']}\n\nlabels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']\ndf2 = pd.DataFrame(data, index=labels)\ndf2\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">    animal  age visits  priority\na   cat      2.5    1   yes\nb   cat      3.0    3   yes\nc   snake    0.5    2   no\nd   dog      NaN    3   yes\ne   dog      5.0    2   no\nf   cat      2.0    3   no\ng   snake    4.5    1   no\nh   cat      NaN    1   yes\ni   dog      7.0    2   no\nj   dog      3.0    1   no\n<\/code><\/pre>\n<h3>5.3 \u67e5\u770b DataFrame \u7684\u6570\u636e\u7c7b\u578b<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">df2.dtypes\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">animal       object\nage         float64\nvisits        int64\npriority     object\ndtype: object\n<\/code><\/pre>\n<h2>6.DataFrame \u57fa\u672c\u64cd\u4f5c<\/h2>\n<h3>6.1 \u9884\u89c8 DataFrame \u7684\u524d 5 \u884c\u6570\u636e<\/h3>\n<p>\u6b64\u65b9\u6cd5\u5bf9\u5feb\u901f\u4e86\u89e3\u964c\u751f\u6570\u636e\u96c6\u7ed3\u6784\u5341\u5206\u6709\u7528\u3002<\/p>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">df2.head()   # \u9ed8\u8ba4\u4e3a\u663e\u793a 5 \u884c\uff0c\u53ef\u6839\u636e\u9700\u8981\u5728\u62ec\u53f7\u4e2d\u586b\u5165\u5e0c\u671b\u9884\u89c8\u7684\u884c\u6570\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">   animal   age   visits    priority\na   cat      2.5    1          yes\nb   cat     3.0     3          yes\nc   snake   0.5     2           no\nd   dog     NaN     3          yes\ne   dog     5.0     2           no\n<\/code><\/pre>\n<h3>6.2 \u67e5\u770b DataFrame \u7684\u540e 3 \u884c\u6570\u636e<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">df2.tail(3)\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">   animal   age visits  priority\nh   cat     NaN     1   yes\ni   dog     7.0     2   no\nj   dog     3.0     1   no\n<\/code><\/pre>\n<h3>6.3 \u67e5\u770bDataFrame \u7684\u7d22\u5f15<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">df2.index\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">Index(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'], dtype='object')\n<\/code><\/pre>\n<h3>6.4 \u67e5\u770b DataFrame \u7684\u5217\u540d<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">df2.columns\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">Index(['animal', 'age', 'visits', 'priority'], dtype='object')\n<\/code><\/pre>\n<h3>6.5  \u67e5\u770b DataFrame \u7684\u6570\u503c<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">df2.values\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">array([['cat', 2.5, 1, 'yes'],\n       ['cat', 3.0, 3, 'yes'],\n       ['snake', 0.5, 2, 'no'],\n       ['dog', nan, 3, 'yes'],\n       ['dog', 5.0, 2, 'no'],\n       ['cat', 2.0, 3, 'no'],\n       ['snake', 4.5, 1, 'no'],\n       ['cat', nan, 1, 'yes'],\n       ['dog', 7.0, 2, 'no'],\n       ['dog', 3.0, 1, 'no']], dtype=object)\n<\/code><\/pre>\n<h3>6.6 \u67e5\u770b DataFrame \u7684\u7edf\u8ba1\u6570\u636e<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">df2.describe()\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">             age    visits\ncount   8.000000    10.000000\nmean    3.437500    1.900000\nstd 2.007797    0.875595\nmin 0.500000    1.000000\n25% 2.375000    1.000000\n50% 3.000000    2.000000\n75% 4.625000    2.750000\nmax 7.000000    3.000000\n<\/code><\/pre>\n<h3>6.7 DataFrame \u8f6c\u7f6e\u64cd\u4f5c<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">df2.T\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">         a     b    c   d   e   f   g   h   i   j\nanimal  cat cat snake   dog dog cat snake   cat dog dog\nage 2.5 3   0.5 NaN 5   2   4.5 NaN 7   3\nvisits  1   3   2   3   2   3   1   1   2   1\npriority    yes yes no  yes no  no  no  yes no  no\n<\/code><\/pre>\n<h3>6.8 \u5bf9 DataFrame \u8fdb\u884c\u6309\u5217\u6392\u5e8f<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">df2.sort_values(by='age')  # \u6309 age \u5347\u5e8f\u6392\u5217\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">   animal   age visits  priority\nc   snake   0.5 2   no\nf   cat 2.0 3   no\na   cat 2.5 1   yes\nb   cat 3.0 3   yes\nj   dog 3.0 1   no\ng   snake   4.5 1   no\ne   dog 5.0 2   no\ni   dog 7.0 2   no\nd   dog NaN 3   yes\nh   cat NaN 1   yes\n<\/code><\/pre>\n<h3>6.9 \u5bf9 DataFrame \u6570\u636e\u5207\u7247<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">df2[1:3]\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">    animal  age visits  priority\nb    cat    3.0 3   yes\nc    snake  0.5 2   no\n<\/code><\/pre>\n<h3>6.10 \u5bf9 DataFrame \u901a\u8fc7\u6807\u7b7e\u67e5\u8be2\uff08\u5355\u5217\uff09<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">df2['age']\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">a    2.5\nb    3.0\nc    0.5\nd    NaN\ne    5.0\nf    2.0\ng    4.5\nh    NaN\ni    7.0\nj    3.0\nName: age, dtype: float64\n<\/code><\/pre>\n<p>\u6216\uff1a<br \/>\n\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">df2.age  # \u7b49\u4ef7\u4e8e df2['age']\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">a    2.5\nb    3.0\nc    0.5\nd    NaN\ne    5.0\nf    2.0\ng    4.5\nh    NaN\ni    7.0\nj    3.0\nName: age, dtype: float64\n<\/code><\/pre>\n<h3>6.11 \u5bf9 DataFrame \u901a\u8fc7\u6807\u7b7e\u67e5\u8be2\uff08\u591a\u5217\uff09<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">df2[['age', 'animal']]  # \u4f20\u5165\u4e00\u4e2a\u5217\u540d\u7ec4\u6210\u7684\u5217\u8868\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">    age animal\na   2.5 cat\nb   3.0 cat\nc   0.5 snake\nd   NaN dog\ne   5.0 dog\nf   2.0 cat\ng   4.5 snake\nh   NaN cat\ni   7.0 dog\nj   3.0 dog\n<\/code><\/pre>\n<h3>6.12 \u5bf9 DataFrame \u901a\u8fc7\u4f4d\u7f6e\u67e5\u8be2<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">df2.iloc[1:3]  # \u67e5\u8be2 2\uff0c3 \u884c\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">    animal  age visits  priority\nb   cat      3.0    3   yes\nc   snake    0.5    2   no\n<\/code><\/pre>\n<h3>6.13 DataFrame \u526f\u672c\u62f7\u8d1d<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\"># \u751f\u6210 DataFrame \u526f\u672c\uff0c\u65b9\u4fbf\u6570\u636e\u96c6\u88ab\u591a\u4e2a\u4e0d\u540c\u6d41\u7a0b\u4f7f\u7528\ndf3 = df2.copy()\ndf3\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">    animal  age visits  priority\na   cat 2.5 1   yes\nb   cat 3.0 3   yes\nc   snake   0.5 2   no\nd   dog NaN 3   yes\ne   dog 5.0 2   no\nf   cat 2.0 3   no\ng   snake   4.5 1   no\nh   cat NaN 1   yes\ni   dog 7.0 2   no\nj   dog 3.0 1   no\n<\/code><\/pre>\n<h3>6.14 \u5224\u65ad DataFrame \u5143\u7d20\u662f\u5426\u4e3a\u7a7a<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">df3.isnull()  # \u5982\u679c\u4e3a\u7a7a\u5219\u8fd4\u56de\u4e3a True\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">    animal  age visits  priority\na   False   False   False   False\nb   False   False   False   False\nc   False   False   False   False\nd   False   True    False   False\ne   False   False   False   False\nf   False   False   False   False\ng   False   False   False   False\nh   False   True    False   False\ni   False   False   False   False\nj   False   False   False   False\n<\/code><\/pre>\n<h3>6.15 \u6dfb\u52a0\u5217\u6570\u636e<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">num = pd.Series([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], index=df3.index)\n\ndf3['No.'] = num  # \u6dfb\u52a0\u4ee5 'No.' \u4e3a\u5217\u540d\u7684\u65b0\u6570\u636e\u5217\ndf3\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\"><br \/>animal  age visits  priority    No.\na   cat 2.5 1   yes 0\nb   cat 3.0 3   yes 1\nc   snake   0.5 2   no  2\nd   dog NaN 3   yes 3\ne   dog 5.0 2   no  4\nf   cat 2.0 3   no  5\ng   snake   4.5 1   no  6\nh   cat NaN 1   yes 7\ni   dog 7.0 2   no  8\nj   dog 3.0 1   no  9\n<\/code><\/pre>\n<h3>6.16 \u6839\u636e DataFrame \u7684\u4e0b\u6807\u503c\u8fdb\u884c\u66f4\u6539<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\"># \u4fee\u6539\u7b2c 2 \u884c\u4e0e\u7b2c 1 \u5217\u5bf9\u5e94\u7684\u503c 3.0 \u2192 2.0\ndf3.iat[1, 0] = 2  # \u7d22\u5f15\u5e8f\u53f7\u4ece 0 \u5f00\u59cb\uff0c\u8fd9\u91cc\u4e3a 1, 0\ndf3\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\"><br \/>animal  age visits  priority    No.\na   cat 2.5 1   yes 0\nb   2   3.0 3   yes 1\nc   snake   0.5 2   no  2\nd   dog NaN 3   yes 3\ne   dog 5.0 2   no  4\nf   cat 2.0 3   no  5\ng   snake   4.5 1   no  6\nh   cat NaN 1   yes 7\ni   dog 7.0 2   no  8\nj   dog 3.0 1   no  9\n<\/code><\/pre>\n<h3>6.17 \u6839\u636e DataFrame \u7684\u6807\u7b7e\u5bf9\u6570\u636e\u8fdb\u884c\u4fee\u6539<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">df3.loc['f', 'age'] = 1.5\ndf3\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">   animal   age visits  priority\na   cat 2.5 1   yes\nb   cat 3.0 3   yes\nc   snake   0.5 2   no\nd   dog NaN 3   yes\ne   dog 5.0 2   no\nf   cat 1.5 3   no\ng   snake   4.5 1   no\nh   cat NaN 1   yes\ni   dog 7.0 2   no\nj   dog 3.0 1   no\n<\/code><\/pre>\n<h3>6.18 DataFrame \u6c42\u5e73\u5747\u503c\u64cd\u4f5c<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">df3.mean()\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">age       3.375\nvisits    1.900\ndtype: float64\n<\/code><\/pre>\n<h3>6.19 \u5bf9 DataFrame \u4e2d\u4efb\u610f\u5217\u505a\u6c42\u548c\u64cd\u4f5c<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">df3['visits'].sum()\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">19\n<\/code><\/pre>\n<h2>7.\u5b57\u7b26\u4e32\u64cd\u4f5c<\/h2>\n<h3>7.1 \u5c06\u5b57\u7b26\u4e32\u8f6c\u5316\u4e3a\u5c0f\u5199\u5b57\u6bcd<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">string = pd.Series(['A', 'B', 'C', 'Aaba', 'Baca',\n                    np.nan, 'CABA', 'dog', 'cat'])\nprint(string)\nstring.str.lower()\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">0       A\n1       B\n2       C\n3    Aaba\n4    Baca\n5     NaN\n6    CABA\n7    dog \n8     cat\n\ndtype: object\n0       a\n1       b\n2       c\n3    aaba\n4    baca\n5     NaN\n6    caba\n7    dog \n8     cat\ndtype: object\n<\/code><\/pre>\n<h3>7.2 \u5c06\u5b57\u7b26\u4e32\u8f6c\u5316\u4e3a\u5927\u5199\u5b57\u6bcd<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">string.str.upper()\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">0       A\n1       B\n2       C\n3    AABA\n4    BACA\n5     NaN\n6    CABA\n7    DOG \n8     CAT\ndtype: object\n<\/code><\/pre>\n<h2>8. DataFrame \u7f3a\u5931\u503c\u64cd\u4f5c<\/h2>\n<h3>8.1 \u5bf9\u7f3a\u5931\u503c\u8fdb\u884c\u586b\u5145<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">df4 = df3.copy()\nprint(df4)\ndf4.fillna(value=3)\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">   animal  age  visits priority\na    cat  2.5       1      yes\nb    cat  3.0       3      yes\nc  snake  0.5       2       no\nd    dog  NaN       3      yes\ne    dog  5.0       2       no\nf    cat  1.5       3       no\ng  snake  4.5       1       no\nh    cat  NaN       1      yes\ni    dog  7.0       2       no\nj    dog  3.0       1       no\n\n  animal    age visits  priority\na   cat 2.5 1   yes\nb   cat 3.0 3   yes\nc   snake   0.5 2   no\nd   dog 3.0 3   yes\ne   dog 5.0 2   no\nf   cat 1.5 3   no\ng   snake   4.5 1   no\nh   cat 3.0 1   yes\ni   dog 7.0 2   no\nj   dog 3.0 1   no\n<\/code><\/pre>\n<h3>8.2 \u5220\u9664\u5b58\u5728\u7f3a\u5931\u503c\u7684\u884c<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">df5 = df3.copy()\nprint(df5)\ndf5.dropna(how='any')  # \u4efb\u4f55\u5b58\u5728 NaN \u7684\u884c\u90fd\u5c06\u88ab\u5220\u9664\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">   animal  age  visits priority\na    cat  2.5       1      yes\nb    cat  3.0       3      yes\nc  snake  0.5       2       no\nd    dog  NaN       3      yes\ne    dog  5.0       2       no\nf    cat  1.5       3       no\ng  snake  4.5       1       no\nh    cat  NaN       1      yes\ni    dog  7.0       2       no\nj    dog  3.0       1       no\n\n  animal    age visits  priority\na   cat 2.5 1   yes\nb   cat 3.0 3   yes\nc   snake   0.5 2   no\ne   dog 5.0 2   no\nf   cat 1.5 3   no\ng   snake   4.5 1   no\ni   dog 7.0 2   no\nj   dog 3.0 1   no\n<\/code><\/pre>\n<h3>8.3 DataFrame \u6309\u6307\u5b9a\u5217\u5bf9\u9f50<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">left = pd.DataFrame({'key': ['foo1', 'foo2'], 'one': [1, 2]})\nright = pd.DataFrame({'key': ['foo2', 'foo3'], 'two': [4, 5]})\n\nprint(left)\nprint(right)\n\n# \u6309\u7167 key \u5217\u5bf9\u9f50\u8fde\u63a5\uff0c\u53ea\u5b58\u5728 foo2 \u76f8\u540c\uff0c\u6240\u4ee5\u6700\u540e\u53d8\u6210\u4e00\u884c\npd.merge(left, right, on='key')\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\"> key  one\n0  foo1    1\n1  foo2    2\n\n key  two\n0  foo2    4\n1  foo3    5\n\n key    one two\n0   foo2    2   4\n<\/code><\/pre>\n<h2>9.DataFrame \u6587\u4ef6\u64cd\u4f5c<\/h2>\n<h3>9.1 CSV \u6587\u4ef6\u5199\u5165<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">df3.to_csv('animal.csv')\nprint(\"\u5199\u5165\u6210\u529f.\")\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">\u5199\u5165\u6210\u529f.\n<\/code><\/pre>\n<h3>9.2 CSV \u6587\u4ef6\u8bfb\u53d6<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">df_animal = pd.read_csv('animal.csv')\ndf_animal\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">    Unnamed: 0  animal  age visits  priority\n0   a   cat 2.5 1   yes\n1   b   cat 3.0 3   yes\n2   c   snake   0.5 2   no\n3   d   dog NaN 3   yes\n4   e   dog 5.0 2   no\n5   f   cat 1.5 3   no\n6   g   snake   4.5 1   no\n7   h   cat NaN 1   yes\n8   i   dog 7.0 2   no\n9   j   dog 3.0 1   no\n<\/code><\/pre>\n<h3>9.3 Excel \u5199\u5165\u64cd\u4f5c<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">df3.to_excel('animal.xlsx', sheet_name='Sheet1')\nprint(\"\u5199\u5165\u6210\u529f.\")\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">\u5199\u5165\u6210\u529f.\n<\/code><\/pre>\n<h3>9.4 Excel \u8bfb\u53d6\u64cd\u4f5c<\/h3>\n<p>\u8f93\u5165\uff1a<\/p>\n<pre><code class=\"\">pd.read_excel('animal.xlsx', 'Sheet1', index_col=None, na_values=['NA'])\n<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"\">    animal  age visits  priority\na   cat 2.5 1   yes\nb   cat 3.0 3   yes\nc   snake   0.5 2   no\nd   dog NaN 3   yes\ne   dog 5.0 2   no\nf   cat 1.5 3   no\ng   snake   4.5 1   no\nh   cat NaN 1   yes\ni   dog 7.0 2   no\nj   dog 3.0 1   no\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4ecb\u7ecd Pandas \u662f\u57fa\u4e8e NumPy \u7684\u4e00\u79cd\u6570\u636e\u5904\u7406\u5de5\u5177\uff0c\u8be5\u5de5\u5177\u4e3a\u4e86\u89e3\u51b3\u6570\u636e\u5206\u6790\u4efb\u52a1\u800c\u521b\u5efa\u3002Pandas \u7eb3\u5165\u4e86\u5927\u91cf\u5e93\u548c\u4e00\u4e9b\u6807\u51c6\u7684\u6570\u636e\u6a21\u578b\uff0c\u63d0\u4f9b\u4e86\u9ad8\u6548\u5730\u64cd\u4f5c\u5927\u578b\u6570\u636e\u96c6\u6240\u9700\u7684\u51fd\u6570\u548c\u65b9\u6cd5\u3002 Pandas \u7684\u6570\u636e\u7ed3\u6784\uff1aPandas \u4e3b\u8981\u6709 Series\uff08\u4e00\u7ef4\u6570\u7ec4\uff09\uff0cDataFrame\uff08\u4e8c\u7ef4\u6570\u7ec4\uff09\uff0cPanel\uff08\u4e09\u7ef4\u6570\u7ec4\uff09\uff0cPanel4D\uff08\u56db\u7ef4\u6570\u7ec4\uff09\uff0cPanelND\uff08\u66f4\u591a\u7ef4\u6570\u7ec4\uff09\u7b49\u6570\u636e\u7ed3\u6784\u3002\u5176\u4e2d Series \u548c DataFrame \u5e94\u7528\u7684\u6700\u4e3a\u5e7f\u6cdb\u3002 &#8211; Series \u662f\u4e00\u7ef4\u5e26\u6807\u7b7e\u7684\u6570\u7ec4\uff0c\u5b83\u53ef\u4ee5\u5305\u542b\u4efb\u4f55\u6570\u636e\u7c7b\u578b\u3002\u5305\u62ec\u6574\u6570\uff0c\u5b57\u7b26\u4e32\uff0c\u6d6e\u70b9\u6570\uff0cPython \u5bf9\u8c61\u7b49\u3002Series \u53ef\u4ee5\u901a\u8fc7\u6807\u7b7e\u6765\u5b9a\u4f4d\u3002 &#8211; DataFrame \u662f\u4e8c\u7ef4\u7684\u5e26\u6807\u7b7e\u7684\u6570\u636e\u7ed3\u6784\u3002==\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6807\u7b7e\u6765\u5b9a\u4f4d\u6570\u636e\u3002\u8fd9\u662f NumPy \u6240\u6ca1\u6709\u7684\u3002== \u77e5\u8bc6\u70b9 \u672c\u6b21\u5b9e\u9a8c\u6d89\u53ca\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u6709\uff1a &#8211; \u521b\u5efaSeries &#8211; Series\u57fa\u672c\u64cd\u4f5c &#8211; \u521b\u5efaDataFrame &#8211; DataFrame\u57fa\u672c\u64cd\u4f5c &#8211; DataFrame\u6587\u4ef6\u64cd\u4f5c &#8211; Series\uff0cDataFrame\u548c\u591a\u7d22\u5f15 &#8211; \u900f\u89c6\u8868 &#8211; \u6570\u636e\u6e05\u6d17 &#8211; \u6570\u636e\u9884\u5904\u7406 &#8211; \u53ef\u89c6\u5316 \u57fa\u7840\u90e8\u5206 1.\u5bfc\u5165 Pandas \u6a21\u5757 1. \u5bfc\u5165 Pandas \u8f93\u5165\uff1a import [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":46,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[86,3,2],"tags":[14,10,11],"class_list":["post-42","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dev","category-ml","category-py","tag-pandas","tag-python","tag-11"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Pandas \u8bed\u6cd5\u603b\u7ed3 - Nemo<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/nemo.cool\/42.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Pandas \u8bed\u6cd5\u603b\u7ed3 - Nemo\" \/>\n<meta property=\"og:description\" content=\"\u4ecb\u7ecd Pandas \u662f\u57fa\u4e8e NumPy \u7684\u4e00\u79cd\u6570\u636e\u5904\u7406\u5de5\u5177\uff0c\u8be5\u5de5\u5177\u4e3a\u4e86\u89e3\u51b3\u6570\u636e\u5206\u6790\u4efb\u52a1\u800c\u521b\u5efa\u3002Pandas \u7eb3\u5165\u4e86\u5927\u91cf\u5e93\u548c\u4e00\u4e9b\u6807\u51c6\u7684\u6570\u636e\u6a21\u578b\uff0c\u63d0\u4f9b\u4e86\u9ad8\u6548\u5730\u64cd\u4f5c\u5927\u578b\u6570\u636e\u96c6\u6240\u9700\u7684\u51fd\u6570\u548c\u65b9\u6cd5\u3002 Pandas \u7684\u6570\u636e\u7ed3\u6784\uff1aPandas \u4e3b\u8981\u6709 Series\uff08\u4e00\u7ef4\u6570\u7ec4\uff09\uff0cDataFrame\uff08\u4e8c\u7ef4\u6570\u7ec4\uff09\uff0cPanel\uff08\u4e09\u7ef4\u6570\u7ec4\uff09\uff0cPanel4D\uff08\u56db\u7ef4\u6570\u7ec4\uff09\uff0cPanelND\uff08\u66f4\u591a\u7ef4\u6570\u7ec4\uff09\u7b49\u6570\u636e\u7ed3\u6784\u3002\u5176\u4e2d Series \u548c DataFrame \u5e94\u7528\u7684\u6700\u4e3a\u5e7f\u6cdb\u3002 &#8211; Series \u662f\u4e00\u7ef4\u5e26\u6807\u7b7e\u7684\u6570\u7ec4\uff0c\u5b83\u53ef\u4ee5\u5305\u542b\u4efb\u4f55\u6570\u636e\u7c7b\u578b\u3002\u5305\u62ec\u6574\u6570\uff0c\u5b57\u7b26\u4e32\uff0c\u6d6e\u70b9\u6570\uff0cPython \u5bf9\u8c61\u7b49\u3002Series \u53ef\u4ee5\u901a\u8fc7\u6807\u7b7e\u6765\u5b9a\u4f4d\u3002 &#8211; DataFrame \u662f\u4e8c\u7ef4\u7684\u5e26\u6807\u7b7e\u7684\u6570\u636e\u7ed3\u6784\u3002==\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6807\u7b7e\u6765\u5b9a\u4f4d\u6570\u636e\u3002\u8fd9\u662f NumPy \u6240\u6ca1\u6709\u7684\u3002== \u77e5\u8bc6\u70b9 \u672c\u6b21\u5b9e\u9a8c\u6d89\u53ca\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u6709\uff1a &#8211; \u521b\u5efaSeries &#8211; Series\u57fa\u672c\u64cd\u4f5c &#8211; \u521b\u5efaDataFrame &#8211; DataFrame\u57fa\u672c\u64cd\u4f5c &#8211; DataFrame\u6587\u4ef6\u64cd\u4f5c &#8211; Series\uff0cDataFrame\u548c\u591a\u7d22\u5f15 &#8211; \u900f\u89c6\u8868 &#8211; \u6570\u636e\u6e05\u6d17 &#8211; \u6570\u636e\u9884\u5904\u7406 &#8211; \u53ef\u89c6\u5316 \u57fa\u7840\u90e8\u5206 1.\u5bfc\u5165 Pandas \u6a21\u5757 1. \u5bfc\u5165 Pandas \u8f93\u5165\uff1a import [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/nemo.cool\/42.html\" \/>\n<meta property=\"og:site_name\" content=\"Nemo\" \/>\n<meta property=\"article:published_time\" content=\"2019-05-08T14:41:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-26T07:51:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/nemo.cool\/wp-content\/uploads\/2019\/05\/pandas.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1080\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Nemo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nemo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/nemo.cool\\\/42.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/42.html\"},\"author\":{\"name\":\"Nemo\",\"@id\":\"https:\\\/\\\/nemo.cool\\\/#\\\/schema\\\/person\\\/698f803ee811e2b140a90f5d5de913d2\"},\"headline\":\"Pandas \u8bed\u6cd5\u603b\u7ed3\",\"datePublished\":\"2019-05-08T14:41:29+00:00\",\"dateModified\":\"2024-11-26T07:51:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/42.html\"},\"wordCount\":103,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/#\\\/schema\\\/person\\\/698f803ee811e2b140a90f5d5de913d2\"},\"image\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/42.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/pandas.jpg\",\"keywords\":[\"pandas\",\"python\",\"\u673a\u5668\u5b66\u4e60\"],\"articleSection\":[\"Dev\",\"ML\",\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/nemo.cool\\\/42.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/nemo.cool\\\/42.html\",\"url\":\"https:\\\/\\\/nemo.cool\\\/42.html\",\"name\":\"Pandas \u8bed\u6cd5\u603b\u7ed3 - Nemo\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/42.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/42.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/pandas.jpg\",\"datePublished\":\"2019-05-08T14:41:29+00:00\",\"dateModified\":\"2024-11-26T07:51:26+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/42.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/nemo.cool\\\/42.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/nemo.cool\\\/42.html#primaryimage\",\"url\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/pandas.jpg\",\"contentUrl\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/pandas.jpg\",\"width\":1080,\"height\":675},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/nemo.cool\\\/42.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\\\/\\\/nemo.cool\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Pandas \u8bed\u6cd5\u603b\u7ed3\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/nemo.cool\\\/#website\",\"url\":\"https:\\\/\\\/nemo.cool\\\/\",\"name\":\"Nemo\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/#\\\/schema\\\/person\\\/698f803ee811e2b140a90f5d5de913d2\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/nemo.cool\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/nemo.cool\\\/#\\\/schema\\\/person\\\/698f803ee811e2b140a90f5d5de913d2\",\"name\":\"Nemo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg\",\"url\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg\",\"contentUrl\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg\",\"caption\":\"Nemo\"},\"logo\":{\"@id\":\"https:\\\/\\\/nemo.cool\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg\"},\"sameAs\":[\"https:\\\/\\\/nemo.cool\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Pandas \u8bed\u6cd5\u603b\u7ed3 - Nemo","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/nemo.cool\/42.html","og_locale":"en_US","og_type":"article","og_title":"Pandas \u8bed\u6cd5\u603b\u7ed3 - Nemo","og_description":"\u4ecb\u7ecd Pandas \u662f\u57fa\u4e8e NumPy \u7684\u4e00\u79cd\u6570\u636e\u5904\u7406\u5de5\u5177\uff0c\u8be5\u5de5\u5177\u4e3a\u4e86\u89e3\u51b3\u6570\u636e\u5206\u6790\u4efb\u52a1\u800c\u521b\u5efa\u3002Pandas \u7eb3\u5165\u4e86\u5927\u91cf\u5e93\u548c\u4e00\u4e9b\u6807\u51c6\u7684\u6570\u636e\u6a21\u578b\uff0c\u63d0\u4f9b\u4e86\u9ad8\u6548\u5730\u64cd\u4f5c\u5927\u578b\u6570\u636e\u96c6\u6240\u9700\u7684\u51fd\u6570\u548c\u65b9\u6cd5\u3002 Pandas \u7684\u6570\u636e\u7ed3\u6784\uff1aPandas \u4e3b\u8981\u6709 Series\uff08\u4e00\u7ef4\u6570\u7ec4\uff09\uff0cDataFrame\uff08\u4e8c\u7ef4\u6570\u7ec4\uff09\uff0cPanel\uff08\u4e09\u7ef4\u6570\u7ec4\uff09\uff0cPanel4D\uff08\u56db\u7ef4\u6570\u7ec4\uff09\uff0cPanelND\uff08\u66f4\u591a\u7ef4\u6570\u7ec4\uff09\u7b49\u6570\u636e\u7ed3\u6784\u3002\u5176\u4e2d Series \u548c DataFrame \u5e94\u7528\u7684\u6700\u4e3a\u5e7f\u6cdb\u3002 &#8211; Series \u662f\u4e00\u7ef4\u5e26\u6807\u7b7e\u7684\u6570\u7ec4\uff0c\u5b83\u53ef\u4ee5\u5305\u542b\u4efb\u4f55\u6570\u636e\u7c7b\u578b\u3002\u5305\u62ec\u6574\u6570\uff0c\u5b57\u7b26\u4e32\uff0c\u6d6e\u70b9\u6570\uff0cPython \u5bf9\u8c61\u7b49\u3002Series \u53ef\u4ee5\u901a\u8fc7\u6807\u7b7e\u6765\u5b9a\u4f4d\u3002 &#8211; DataFrame \u662f\u4e8c\u7ef4\u7684\u5e26\u6807\u7b7e\u7684\u6570\u636e\u7ed3\u6784\u3002==\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6807\u7b7e\u6765\u5b9a\u4f4d\u6570\u636e\u3002\u8fd9\u662f NumPy \u6240\u6ca1\u6709\u7684\u3002== \u77e5\u8bc6\u70b9 \u672c\u6b21\u5b9e\u9a8c\u6d89\u53ca\u7684\u77e5\u8bc6\u70b9\u4e3b\u8981\u6709\uff1a &#8211; \u521b\u5efaSeries &#8211; Series\u57fa\u672c\u64cd\u4f5c &#8211; \u521b\u5efaDataFrame &#8211; DataFrame\u57fa\u672c\u64cd\u4f5c &#8211; DataFrame\u6587\u4ef6\u64cd\u4f5c &#8211; Series\uff0cDataFrame\u548c\u591a\u7d22\u5f15 &#8211; \u900f\u89c6\u8868 &#8211; \u6570\u636e\u6e05\u6d17 &#8211; \u6570\u636e\u9884\u5904\u7406 &#8211; \u53ef\u89c6\u5316 \u57fa\u7840\u90e8\u5206 1.\u5bfc\u5165 Pandas \u6a21\u5757 1. \u5bfc\u5165 Pandas \u8f93\u5165\uff1a import [&hellip;]","og_url":"https:\/\/nemo.cool\/42.html","og_site_name":"Nemo","article_published_time":"2019-05-08T14:41:29+00:00","article_modified_time":"2024-11-26T07:51:26+00:00","og_image":[{"width":1080,"height":675,"url":"https:\/\/nemo.cool\/wp-content\/uploads\/2019\/05\/pandas.jpg","type":"image\/jpeg"}],"author":"Nemo","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Nemo","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/nemo.cool\/42.html#article","isPartOf":{"@id":"https:\/\/nemo.cool\/42.html"},"author":{"name":"Nemo","@id":"https:\/\/nemo.cool\/#\/schema\/person\/698f803ee811e2b140a90f5d5de913d2"},"headline":"Pandas \u8bed\u6cd5\u603b\u7ed3","datePublished":"2019-05-08T14:41:29+00:00","dateModified":"2024-11-26T07:51:26+00:00","mainEntityOfPage":{"@id":"https:\/\/nemo.cool\/42.html"},"wordCount":103,"commentCount":0,"publisher":{"@id":"https:\/\/nemo.cool\/#\/schema\/person\/698f803ee811e2b140a90f5d5de913d2"},"image":{"@id":"https:\/\/nemo.cool\/42.html#primaryimage"},"thumbnailUrl":"https:\/\/nemo.cool\/wp-content\/uploads\/2019\/05\/pandas.jpg","keywords":["pandas","python","\u673a\u5668\u5b66\u4e60"],"articleSection":["Dev","ML","Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/nemo.cool\/42.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/nemo.cool\/42.html","url":"https:\/\/nemo.cool\/42.html","name":"Pandas \u8bed\u6cd5\u603b\u7ed3 - Nemo","isPartOf":{"@id":"https:\/\/nemo.cool\/#website"},"primaryImageOfPage":{"@id":"https:\/\/nemo.cool\/42.html#primaryimage"},"image":{"@id":"https:\/\/nemo.cool\/42.html#primaryimage"},"thumbnailUrl":"https:\/\/nemo.cool\/wp-content\/uploads\/2019\/05\/pandas.jpg","datePublished":"2019-05-08T14:41:29+00:00","dateModified":"2024-11-26T07:51:26+00:00","breadcrumb":{"@id":"https:\/\/nemo.cool\/42.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/nemo.cool\/42.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/nemo.cool\/42.html#primaryimage","url":"https:\/\/nemo.cool\/wp-content\/uploads\/2019\/05\/pandas.jpg","contentUrl":"https:\/\/nemo.cool\/wp-content\/uploads\/2019\/05\/pandas.jpg","width":1080,"height":675},{"@type":"BreadcrumbList","@id":"https:\/\/nemo.cool\/42.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/nemo.cool\/"},{"@type":"ListItem","position":2,"name":"Pandas \u8bed\u6cd5\u603b\u7ed3"}]},{"@type":"WebSite","@id":"https:\/\/nemo.cool\/#website","url":"https:\/\/nemo.cool\/","name":"Nemo","description":"","publisher":{"@id":"https:\/\/nemo.cool\/#\/schema\/person\/698f803ee811e2b140a90f5d5de913d2"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/nemo.cool\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/nemo.cool\/#\/schema\/person\/698f803ee811e2b140a90f5d5de913d2","name":"Nemo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/nemo.cool\/wp-content\/uploads\/2024\/01\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg","url":"https:\/\/nemo.cool\/wp-content\/uploads\/2024\/01\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg","contentUrl":"https:\/\/nemo.cool\/wp-content\/uploads\/2024\/01\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg","caption":"Nemo"},"logo":{"@id":"https:\/\/nemo.cool\/wp-content\/uploads\/2024\/01\/Big_Hero_6_Anime_HD_desktop_wallpaper_01_1366x768-e1706020097529-96x96.jpg"},"sameAs":["https:\/\/nemo.cool"]}]}},"_links":{"self":[{"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/posts\/42","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/comments?post=42"}],"version-history":[{"count":0,"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/posts\/42\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/media\/46"}],"wp:attachment":[{"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/media?parent=42"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/categories?post=42"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nemo.cool\/wp-json\/wp\/v2\/tags?post=42"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}