{"id":2811,"date":"2019-10-29T14:23:32","date_gmt":"2019-10-29T05:23:32","guid":{"rendered":"https:\/\/www.dogrow.net\/python\/?p=2811"},"modified":"2019-10-29T14:26:56","modified_gmt":"2019-10-29T05:26:56","slug":"blog109","status":"publish","type":"post","link":"https:\/\/www.dogrow.net\/python\/blog109\/","title":{"rendered":"(109) pandas\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\uff1a\u4e00\u6b21\u5143\u30c7\u30fc\u30bf\u3092\u6271\u3046"},"content":{"rendered":"<h1 class=\"my_h\">1. \u3084\u308a\u305f\u3044\u3053\u3068<\/h1>\n<p><span class=\"my_fc_deeppinkBBig\">pandas<\/span> \u306e <span class=\"my_fc_deeppinkBBig\">Series<\/span> \u578b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u308a\u3001\u4e00\u6b21\u5143\u30c7\u30fc\u30bf\u3092\u6271\u3044\u305f\u3044\u3002<\/p>\n<h1 class=\"my_h\">2. \u3084\u3063\u3066\u307f\u308b<\/h1>\n<p>\u307e\u305a\u306f Python\u3092\u8d77\u52d5\u3057\u3066\u304a\u304f\u3002<\/p>\n<pre class=\"my_pre\">\r\n$ python\r\nPython 3.6.2 |Anaconda custom (64-bit)| (default, Jul 20 2017, 13:51:32)\r\n[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux\r\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\r\n>>>\r\n<\/pre>\n<h3 class=\"my_h\">(1) \u7c21\u5358\u306a\u4e00\u6b21\u5143\u30c7\u30fc\u30bf\u3092\u6271\u3046\u3002<\/h3>\n<p><span class=\"my_fc_deeppinkBBig\">pandas.Series<\/span> \u3067\u306f\u3001\u4e00\u6b21\u5143\u30c7\u30fc\u30bf\u3092\u4f5c\u308c\u308b\u3002<\/p>\n<pre class=\"my_pre_python\">\r\n>>> import pandas as pd            <span class=\"my_fc_green\"># pandas\u30d1\u30c3\u30b1\u30fc\u30b8\u3092\u8aad\u307f\u8fbc\u3080\u3002<\/span>\r\n>>>\r\n>>> data = [1,5,2,3,7,4,6]         <span class=\"my_fc_green\"># \u30ea\u30b9\u30c8\u578b\u30c7\u30fc\u30bf\u3092\u4f5c\u308b\u3002<\/span>\r\n>>> a = pd.Series(data)            <span class=\"my_fc_green\"># Pandas\u306e Series\u578b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u5909\u6570 a\u3068\u3057\u3066\u4f5c\u308b\u3002<\/span>\r\n>>> a                              <span class=\"my_fc_green\"># \u5909\u6570 a\u306e\u4e2d\u8eab\u3092\u8868\u793a\u3059\u308b\u3002<\/span>\r\n0    1\r\n1    5\r\n2    2\r\n3    3\r\n4    7\r\n5    4\r\n6    6\r\ndtype: int64\r\n<\/pre>\n<p>\u751f\u6210\u3055\u308c\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30c7\u30fc\u30bf\u578b\u3092\u898b\u3066\u307f\u308b\u3002<\/p>\n<pre class=\"my_pre_python\">\r\n>>> type(a)\r\n&lt;class 'pandas.core.series.Series'&gt;\r\n<\/pre>\n<p>\u30c7\u30fc\u30bf\u306e\u500b\u6570\u3092\u78ba\u8a8d\u3059\u308b\u3002<\/p>\n<pre class=\"my_pre_python\">\r\n>>> len(a)\r\n7\r\n<\/pre>\n<p>n\u756a\u76ee\u306e\u8981\u7d20\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3002<\/p>\n<pre class=\"my_pre_python\">\r\n>>> a[0]\r\n1\r\n>>> a[4]\r\n7\r\n>>> a[6]\r\n6\r\n<\/pre>\n<p>\u6307\u5b9a\u6761\u4ef6\u3092\u6e80\u305f\u3059\u8981\u7d20\u3060\u3051\u3092\u53d6\u5f97\u3059\u308b\u3002<\/p>\n<pre class=\"my_pre_python\">\r\n>>> a[a &gt; 3]\r\n1    5\r\n4    7\r\n5    4\r\n6    6\r\ndtype: int64\r\n>>>\r\n>>> a[a &gt; 5]\r\n4    7\r\n6    6\r\ndtype: int64\r\n<\/pre>\n<p>index\u3092 range\u578b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8(\uff1diterator\u578b)\u3067\u53d6\u5f97\u3067\u304d\u308b\u3002<\/p>\n<pre class=\"my_pre_python\">\r\n>>> a.index\r\nRangeIndex(start=0, stop=7, step=1)\r\n>>>\r\n>>> for i in a.index:\r\n...     print(i)\r\n...\r\n0\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n<\/pre>\n<p>\u5024\u306f values\u3067\u914d\u5217\u3068\u3057\u3066\u53d6\u5f97\u3067\u304d\u308b\u3002<\/p>\n<pre class=\"my_pre_python\">\r\n>>> a.values\r\narray([1, 5, 2, 3, 7, 4, 6])\r\n<\/pre>\n<h3 class=\"my_h\">(2) \u4efb\u610f\u306e\u5024\u3092\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u306b\u6301\u3064\u4e00\u6b21\u5143\u30c7\u30fc\u30bf\u3092\u6271\u3046\u3002<\/h3>\n<p>\u5024\u3068\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u305d\u308c\u305e\u308c\u30ea\u30b9\u30c8\u578b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u3057\u3066\u4f5c\u308a\u3001\u3053\u308c\u3092 pandas.Series\u306b\u5165\u529b\u3057\u3066\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u308b\u3002<\/p>\n<pre class=\"my_pre_python\">\r\n>>> a = [2,5,6,8,3,9,1]                <span class=\"my_fc_green\"># \u5024\u7528\u306e\u30ea\u30b9\u30c8\u578b\u30c7\u30fc\u30bf\u3092\u4f5c\u308b\u3002<\/span>\r\n>>> b = ['z','f','A','h','v','o','J']  <span class=\"my_fc_green\"># \u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u7528\u306e\u30ea\u30b9\u30c8\u578b\u30c7\u30fc\u30bf\u3092\u4f5c\u308b\u3002<\/span>\r\n>>> c = pd.Series(a, index=b)          <span class=\"my_fc_green\"># \u4e00\u6b21\u5143\u30c7\u30fc\u30bf\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u308b\u3002<\/span>\r\n>>> c\r\nz    2\r\nf    5\r\nA    6\r\nh    8\r\nv    3\r\no    9\r\nJ    1\r\ndtype: int64\r\n<\/pre>\n<p>dictionary\u578b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u540c\u69d8\u306b\u3001\u5404\u8981\u7d20\u306b\u540d\u524d\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3067\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3002<br \/>\n\u3082\u3061\u308d\u3093\u6570\u5b57\u3067\u3082\u30a2\u30af\u30bb\u30b9\u3067\u304d\u308b\u3002<\/p>\n<pre class=\"my_pre_python\">\r\n>>> c['z']\r\n2\r\n>>> c[0]\r\n2\r\n>>> c['v']\r\n3\r\n>>> c[4]\r\n3\r\n>>> c['J']\r\n1\r\n<\/pre>\n<p>\u524d\u56de <a href=\"https:\/\/www.dogrow.net\/python\/blog108\/\">(108) pandas\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/a><br \/>\n\u6b21\u56de <a href=\"https:\/\/www.dogrow.net\/python\/blog110\/\">(110) pandas\u306e\u57fa\u672c\u7684\u306a\u4f7f\u3044\u65b9\uff1a\u4e8c\u6b21\u5143\u30c7\u30fc\u30bf\u3092\u6271\u3046<\/a><\/p>\n<hr class=\"my_hr_bottom\">\n","protected":false},"excerpt":{"rendered":"<p>1. \u3084\u308a\u305f\u3044\u3053\u3068 pandas \u306e Series \u578b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u308a\u3001\u4e00\u6b21\u5143\u30c7\u30fc\u30bf\u3092\u6271\u3044\u305f\u3044\u3002 2. \u3084\u3063\u3066\u307f\u308b \u307e\u305a\u306f Python\u3092\u8d77\u52d5\u3057\u3066\u304a\u304f\u3002 $ python Python 3.6.2 |Anaconda \u2026 <span class=\"read-more\"><a href=\"https:\/\/www.dogrow.net\/python\/blog109\/\">\u7d9a\u304d\u3092\u8aad\u3080 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[42],"tags":[],"class_list":["post-2811","post","type-post","status-publish","format-standard","hentry","category-pandas"],"views":4844,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/2811","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/comments?post=2811"}],"version-history":[{"count":4,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/2811\/revisions"}],"predecessor-version":[{"id":2816,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/2811\/revisions\/2816"}],"wp:attachment":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/media?parent=2811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/categories?post=2811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/tags?post=2811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}