{"id":1212,"date":"2024-11-27T19:14:33","date_gmt":"2024-11-27T11:14:33","guid":{"rendered":"https:\/\/gemmartdesign.com\/?p=1212"},"modified":"2024-11-30T01:49:30","modified_gmt":"2024-11-29T17:49:30","slug":"python-post18","status":"publish","type":"post","link":"https:\/\/gemmartdesign.com\/?p=1212","title":{"rendered":"Python\u7df4\u7fd2#18-Pandas\u57fa\u672c\u529f\u80fd"},"content":{"rendered":"\n<h2 class=\"wp-block-heading has-text-color has-link-color wp-elements-6f3c296329a310c4ec4b8858acb7fc91\" style=\"color:#ff8a65\">\u672c\u5468\u76ee\u6a19<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5b78\u7fd2Pandas\u8cc7\u6599\u5206\u6790<\/p>\n\n\n\n<h2 class=\"wp-block-heading has-text-color has-link-color wp-elements-d378f6d1ee3ff41f6cf438efcd397311\" style=\"color:#ff8a65\">\u4efb\u52d9<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8a8d\u8b58\u55ae\u7dad\u5ea6\u7684\u8cc7\u6599 Series <\/li>\n\n\n\n<li>\u8a8d\u8b58\u96d9\u7dad\u5ea6\u7684\u8cc7\u6599 DataFrame\u3002 (\u985e\u4f3c\u8868\u683c\u3001table)<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading has-text-color has-link-color wp-elements-4ff4e1ba3503f9246295601b9b47d959\" style=\"color:#ff8a65\">\u5c08\u6848\u7df4\u7fd2<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f7f\u7528Series\u627e\u51fa\u6700\u5927\u503c\u3001\u4e2d\u4f4d\u6578\u8207\u653e\u59272\u500d<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>import pandas as pd\ndata=pd.Series(&#91;20,25,10,15,20,15,12])\nprint(data)\nprint(\"Max:\",data.max())\nprint(\"Median:\",data.median())\nprint(\"--------------------\")\ndata=data*2\nprint(data)\nprint(\"Max:\",data.max())\nprint(\"Median:\",data.median())<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0    20\n1    25\n2    15\n3    20\n4    12\ndtype: int64\nMax: 25\nMedian: 20.0\n--------------------\n0    40\n1    50\n2    30\n3    40\n4    24\ndtype: int64\nMax: 50\nMedian: 40.0<\/code><\/pre>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u6bd4\u8f03\u904b\u7b97<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>\nimport pandas as pd\ndata=pd.Series(&#91;20,25,15,20,12])\ndata=data==20\nprint(data)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0     True \n1    False \n2    False \n3     True \n4    False \ndtype: bool<\/code><\/pre>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Dataframe\u57fa\u672c\u64cd\u4f5c\uff0c\u53d6\u5f97\u7279\u5b9a\u6b04\u4f4d<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>import pandas as pd\ndata=pd.DataFrame({\n    \"Name\":&#91;\"Amy\",\"Leo\",\"Joy\",\"Candy\"],\n    \"Age\":&#91;20,25,28,\"NA\"]\n})\nprint(data)\n# print(data&#91;\"Name\"])\nprint(\"--------------------\")\nprint(data.iloc&#91;0])\nprint(data.iloc&#91;0,1])<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Output<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>    Name Age\n0    Amy  20\n1    Leo  25\n2    Joy  28\n3  Candy  NA\n--------------------  \nName    Amy\nAge      20\nName: 0, dtype: object\n20<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u5468\u76ee\u6a19 \u5b78\u7fd2Pandas\u8cc7\u6599\u5206\u6790 \u4efb\u52d9 \u5c08\u6848\u7df4\u7fd2 \u4f7f\u7528Se&hellip;<\/p>\n","protected":false},"author":1,"featured_media":1284,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"content-type":"","pagelayer_contact_templates":[],"_pagelayer_content":"","_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[9],"tags":[],"class_list":["post-1212","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=\/wp\/v2\/posts\/1212","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1212"}],"version-history":[{"count":2,"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=\/wp\/v2\/posts\/1212\/revisions"}],"predecessor-version":[{"id":1285,"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=\/wp\/v2\/posts\/1212\/revisions\/1285"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=\/wp\/v2\/media\/1284"}],"wp:attachment":[{"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1212"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1212"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gemmartdesign.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}