{"id":4762,"date":"2022-02-19T01:12:29","date_gmt":"2022-02-18T16:12:29","guid":{"rendered":"https:\/\/obenkyolab.com\/?p=4762"},"modified":"2022-02-19T01:12:29","modified_gmt":"2022-02-18T16:12:29","slug":"%e3%80%90python%e3%80%91%e3%83%87%e3%83%bc%e3%82%bf%e3%83%95%e3%83%ac%e3%83%bc%e3%83%a0%e3%81%a71%e3%81%8c%e5%85%a5%e3%81%a3%e3%81%a6%e3%81%84%e3%82%8b%e5%88%97%e3%82%92%e5%88%a4%e5%ae%9a%e3%81%97","status":"publish","type":"post","link":"https:\/\/obenkyolab.com\/?p=4762","title":{"rendered":"\u3010Python\u3011\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u30671\u304c\u5165\u3063\u3066\u3044\u308b\u5217\u3092\u5224\u5b9a\u3057\u3066\u7d50\u679c\u3092\u4e00\u5217\u306b\u96c6\u7d04\u3059\u308b"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_80 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/obenkyolab.com\/?p=4762\/#%E6%A6%82%E8%A6%81\" >\u6982\u8981<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/obenkyolab.com\/?p=4762\/#%E6%A4%9C%E8%A8%BC%E3%83%87%E3%83%BC%E3%82%BF\" >\u691c\u8a3c\u30c7\u30fc\u30bf<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/obenkyolab.com\/?p=4762\/#%E5%AE%9F%E7%8F%BE%E3%81%99%E3%82%8B%E3%82%B3%E3%83%BC%E3%83%89\" >\u5b9f\u73fe\u3059\u308b\u30b3\u30fc\u30c9<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"\u6982\u8981\"><span class=\"ez-toc-section\" id=\"%E6%A6%82%E8%A6%81\"><\/span>\u6982\u8981<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Python\u306e\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u306eget_dummies\u306e\u7d50\u679c\u306e\u3088\u3046\u306a\u6a2a\u6301\u306e\u30c7\u30fc\u30bf\u304c\u3042\u3063\u305f\u5834\u5408\u306b\u3001\u3069\u306e\u5217\u306b1\u304c\u5165\u3063\u3066\u3044\u308b\u304b\u3092\u5224\u5b9a\u3057\u3066\u7d50\u679c\u3092\u4e00\u5217\u306b\u307e\u3068\u3081\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u8003\u3048\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u691c\u8a3c\u30c7\u30fc\u30bf\"><span class=\"ez-toc-section\" id=\"%E6%A4%9C%E8%A8%BC%E3%83%87%E3%83%BC%E3%82%BF\"><\/span>\u691c\u8a3c\u30c7\u30fc\u30bf<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u4ee5\u4e0b\u306e\u3088\u3046\u306b\uff13\u3064\u306e\u30ab\u30e9\u30e0A, B, C\u306b\u305d\u308c\u305e\u308c1\u304b0\u304c\u5165\u3063\u3066\u3044\u308b\u30c7\u30fc\u30bf\u3092\u7528\u610f\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>import pandas as pd\ndf = pd.DataFrame([[1,1,0],[0,0,1],[1,0,1]],columns = [&#39;A&#39;,&#39;B&#39;,&#39;C&#39;])\ndf.head()<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"102\" height=\"119\" src=\"https:\/\/obenkyolab.com\/wp-content\/uploads\/2022\/02\/image.png\" alt=\"\" class=\"wp-image-4763\"\/><\/figure>\n\n\n\n<p>\u76ee\u6a19\u3068\u3059\u308b\u306e\u306f\u3001\u5404\u884c\u3054\u3068\u306b\u3069\u306e\u5217\u306b1\u304c\u5165\u3063\u3066\u3044\u308b\u304b\u3092\u5224\u5b9a\u3057\u3001\u7d50\u679c\u3092\u4e00\u5217\u3067\u8868\u73fe\u3059\u308b\u3053\u3068\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u5b9f\u73fe\u3059\u308b\u30b3\u30fc\u30c9\"><span class=\"ez-toc-section\" id=\"%E5%AE%9F%E7%8F%BE%E3%81%99%E3%82%8B%E3%82%B3%E3%83%BC%E3%83%89\"><\/span>\u5b9f\u73fe\u3059\u308b\u30b3\u30fc\u30c9<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>df[&#39;judge&#39;] = &#39;&#39;\nfor c in df.columns:\n    df.judge[df==1]=df.judge + c\n\ndf.head()<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"144\" height=\"112\" src=\"https:\/\/obenkyolab.com\/wp-content\/uploads\/2022\/02\/image-1.png\" alt=\"\" class=\"wp-image-4764\"\/><\/figure>\n\n\n\n<p>\u65b9\u5f0f\u3068\u3057\u3066\u306f\u3001\u6700\u521d\u306b\u3000df[&#8216;judge&#8217;] = &#8221;\u3000\u306b\u3088\u3063\u3066\u5224\u5b9a\u7528\u306e\u5217\u3092\u8ffd\u52a0\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p>\u305d\u306e\u5f8c\u3001\u5217\u540d\u6bce\u306b\u30a4\u30c6\u30ec\u30fc\u30b7\u30e7\u30f3\u3067 1\u3068\u306a\u3063\u3066\u3044\u308b\u884c\u3092\u62bd\u51fa\u3057\u305f\u4e0a\u3067\u3001\u8a72\u5f53\u884c\u306ejudge\u5217\u306b\u5217\u540d\u3092\u8ffd\u52a0\u3057\u3066\u3044\u304f\u3068\u3044\u3046\u65b9\u6cd5\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u3053\u306e\u51e6\u7406\u3092\u884c\u3046\u3053\u3068\u306b\u3088\u308a\u3001\u3044\u3061\u3044\u3061\u5168\u90e8\u306e\u5217\u3092\u78ba\u8a8d\u305b\u305a\u3068\u3082\u3001judge\u5217\u3060\u3051\u307f\u308c\u3070\u3069\u306e\u5217\u306b1\u304c\u5165\u3063\u3066\u3044\u308b\u304b\u304c\u5206\u304b\u308a\u307e\u3059\u306e\u3067\u4fbf\u5229\u3067\u3059\u3002<\/p>\n\n\n\n<p>\u306a\u304a\u3001judge\u5217\u306e\u30c7\u30fc\u30bf\u306e\u6841\u6570\u3092\u63c3\u3048\u305f\u3044\u5834\u5408\u306f\u30a2\u30f3\u30c0\u30fc\u30b9\u30b3\u30a2\u306a\u3069\u3092\u5165\u308c\u3066\u3044\u304f\u306e\u3082\u826f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-python\" data-lang=\"Python\"><code>import pandas as pd\ndf = pd.DataFrame([[1,1,0],[0,0,1],[1,0,1]],columns = [&#39;A&#39;,&#39;B&#39;,&#39;C&#39;])\ndf[&#39;judge&#39;] = &#39;&#39;\nfor c in df.columns:\n    df.judge[df==1] = df.judge + c\n    df.judge[df==0] = df.judge + &#39;_&#39;\n\ndf.head()<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/obenkyolab.com\/wp-content\/uploads\/2022\/02\/image-2.png\" alt=\"\" class=\"wp-image-4766\" width=\"197\" height=\"145\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u6982\u8981 Python\u306e\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u306eget_dummies\u306e\u7d50\u679c\u306e\u3088&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":1218,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_locale":"ja","_original_post":"https:\/\/obenkyolab.com\/?p=4762","footnotes":""},"categories":[7],"tags":[93,100],"class_list":["post-4762","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-pandas","tag-100","ja"],"_links":{"self":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts\/4762","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4762"}],"version-history":[{"count":2,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts\/4762\/revisions"}],"predecessor-version":[{"id":4767,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/posts\/4762\/revisions\/4767"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=\/wp\/v2\/media\/1218"}],"wp:attachment":[{"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4762"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4762"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/obenkyolab.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4762"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}