{"id":94,"date":"2019-12-27T22:00:45","date_gmt":"2019-12-27T13:00:45","guid":{"rendered":"https:\/\/obgyn.jp\/?p=94"},"modified":"2022-03-13T19:52:54","modified_gmt":"2022-03-13T10:52:54","slug":"pivot-table","status":"publish","type":"post","link":"https:\/\/obgyn.jp\/?p=94","title":{"rendered":"Python \u306b\u3088\u308b\u30af\u30ed\u30b9\u96c6\u8a08\u8868"},"content":{"rendered":"\n<p><a href=\"https:\/\/pandas.pydata.org\/pandas-docs\/stable\/reference\/api\/pandas.pivot_table.html\" rel=\"noopener noreferrer\" target=\"_blank\">pandas.pivot_table()<\/a> \u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u3044\u3001\u30af\u30ed\u30b9\u96c6\u8a08\u8868\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n\n\n\n<p>Python \u3092\u8d77\u52d5\u3057\u3001pandas \u3092 import \u3059\u308b\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import pandas as pd<\/pre>\n\n\n\n<p>\u901a\u5e38\u306f Excel \u7b49\u3067\u4f5c\u6210\u3057\u305f CSV \u30d5\u30a1\u30a4\u30eb\u3092 pandas \u306b\u8aad\u307f\u8fbc\u3093\u3067\u5206\u6790\u3059\u308b\u3002\u3057\u304b\u3057\u3001\u3053\u3053\u3067\u306f\u4fbf\u5b9c\u7684\u306b\u4ee5\u4e0b\u306e\u7c21\u5358\u306a\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u3092\u4f5c\u6210\u3057\u3001data \u3068\u3044\u3046\u5909\u6570\u306b\u683c\u7d0d\u3057\u3066\u304a\u304f\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">data = pd.DataFrame({\"\u8853\u8005\":[\"\u592a\u90ce\",\"\u82b1\u5b50\",\"\u592a\u90ce\",\"\u82b1\u5b50\",\"\u592a\u90ce\",\"\u82b1\u5b50\"], \"\u624b\u8853\u65b9\u6cd5\":[\"\u5185\u8996\u93e1\",\"\u958b\u8179\",\"\u958b\u8179\",\"\u5185\u8996\u93e1\",\"\u5185\u8996\u93e1\",\"\u5185\u8996\u93e1\"], \"\u624b\u8853\u6642\u9593\":[60,50,100,90,30,40], \"\u51fa\u8840\u91cf\":[15,25,35,55,45,25]})<\/pre>\n\n\n\n<p>data \u306e\u5185\u5bb9\u3092\u78ba\u8a8d\u3059\u308b\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">data<\/pre>\n\n\n\n<p>\u8853\u8005\u3068\u624b\u8853\u65b9\u6cd5\u3067\u3001\u624b\u8853\u6642\u9593\u306e\u5e73\u5747\u304c\u3069\u3046\u7570\u306a\u308b\u304b\u3092\u96c6\u8a08\u3059\u308b\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pd.pivot_table(data, values = \"\u624b\u8853\u6642\u9593\", index = \"\u8853\u8005\", columns = \"\u624b\u8853\u65b9\u6cd5\", aggfunc = \"mean\")<\/pre>\n\n\n\n<p>\u624b\u8853\u6642\u9593\u3060\u3051\u3067\u306a\u304f\u3001\u51fa\u8840\u91cf\u306e\u5e73\u5747\u3082\u96c6\u8a08\u3059\u308b\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pd.pivot_table(data, values = [\"\u624b\u8853\u6642\u9593\", \"\u51fa\u8840\u91cf\"], index = \"\u8853\u8005\", columns = \"\u624b\u8853\u65b9\u6cd5\", aggfunc = \"mean\")<\/pre>\n\n\n\n<p>aggfunc \u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5909\u3048\u3089\u308c\u308b\u3002<br>mean: \u5e73\u5747<br>count: \u30c7\u30fc\u30bf\u306e\u500b\u6570<br>sum: \u5408\u8a08<br>var: \u5206\u6563<br>std: \u6a19\u6e96\u504f\u5dee<br>max: \u6700\u5927\u5024<br>min: \u6700\u5c0f\u5024<br>median: \u4e2d\u592e\u5024<\/p>\n\n\n\n<p>margins = True \u3092\u4ed8\u3051\u52a0\u3048\u308b\u3068\u3001\u5c0f\u8a08\u3092\u8868\u793a\u3059\u308b\u3002\u307e\u305f\u3001aggfunc = &#8220;count&#8221; \u3068\u3059\u308b\u3053\u3068\u3067\u4ef6\u6570\u3092\u8868\u793a\u3059\u308b\u901a\u5e38\u306e\u30af\u30ed\u30b9\u96c6\u8a08\u306b\u306a\u308b\u3002<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">pd.pivot_table(data,values = \"\u624b\u8853\u6642\u9593\", index = \"\u8853\u8005\", columns = \"\u624b\u8853\u65b9\u6cd5\", aggfunc = \"count\", margins = True)<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>pandas.pivot_table() \u30b3\u30de\u30f3\u30c9\u3092\u4f7f\u3044\u3001\u30af\u30ed\u30b9\u96c6\u8a08\u8868\u3092\u4f5c\u6210\u3059\u308b\u3002 Python \u3092\u8d77\u52d5\u3057\u3001pandas \u3092 import \u3059\u308b\u3002 \u901a\u5e38\u306f Excel \u7b49\u3067\u4f5c\u6210\u3057\u305f CSV \u30d5\u30a1\u30a4\u30eb\u3092 pandas \u306b\u8aad &hellip; <a href=\"https:\/\/obgyn.jp\/?p=94\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">Python \u306b\u3088\u308b\u30af\u30ed\u30b9\u96c6\u8a08\u8868<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[36],"class_list":["post-94","post","type-post","status-publish","format-standard","hentry","category-data-science","tag-python"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/obgyn.jp\/index.php?rest_route=\/wp\/v2\/posts\/94","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/obgyn.jp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/obgyn.jp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/obgyn.jp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/obgyn.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=94"}],"version-history":[{"count":24,"href":"https:\/\/obgyn.jp\/index.php?rest_route=\/wp\/v2\/posts\/94\/revisions"}],"predecessor-version":[{"id":1088,"href":"https:\/\/obgyn.jp\/index.php?rest_route=\/wp\/v2\/posts\/94\/revisions\/1088"}],"wp:attachment":[{"href":"https:\/\/obgyn.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/obgyn.jp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/obgyn.jp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}