{"id":12861,"date":"2021-04-11T13:33:31","date_gmt":"2021-04-11T04:33:31","guid":{"rendered":"http:\/\/takuminasuno.com\/?p=12861"},"modified":"2021-05-03T23:36:16","modified_gmt":"2021-05-03T14:36:16","slug":"20210411_python_ja","status":"publish","type":"post","link":"https:\/\/takuminasuno.com\/ja\/20210411_python_ja","title":{"rendered":"Python\u306b\u3088\u308b\u30c7\u30fc\u30bf\u51e6\u7406\u306e\u57fa\u672c\u307e\u3068\u3081\u3010pandas, json, datetime, gzip\u306a\u3069\u3011"},"content":{"rendered":"<p>&#12371;&#12435;&#12395;&#12435;&#12385;&#12399;&#12290;<a href=\"https:\/\/twitter.com\/takumi_nasuno\" target=\"_blank\" rel=\"noopener noreferrer\">&#37027;&#38920;&#37326;<\/a>&#12391;&#12377;&#12290;<p>Python&#12391;&#12487;&#12540;&#12479;&#20966;&#29702;&#12434;&#12377;&#12427;&#12395;&#12354;&#12383;&#12387;&#12390;&#12289;Python&#12394;&#12425;&#12391;&#12399;&#12398;&#33258;&#30001;&#24230;&#12398;&#39640;&#12373;&#12420;&#20182;&#35328;&#35486;&#12392;&#12398;&#24494;&#22937;&#12394;&#24046;&#30064;&#12364;&#27671;&#12395;&#12394;&#12387;&#12390;&#12356;&#12383;&#12398;&#12391;&#12289;&#33258;&#20998;&#12364;&#12424;&#12367;&#26360;&#12367;&#22522;&#26412;&#30340;&#12394;&#20966;&#29702;&#12434;&#12414;&#12392;&#12417;&#12390;&#12415;&#12414;&#12375;&#12383;&#12290;&#25391;&#12426;&#36820;&#12387;&#12390;&#12415;&#12427;&#12392;&#12289;numpy&#12392;&#12363;matlib&#12392;&#12363;&#12399;&#20837;&#12387;&#12390;&#12356;&#12394;&#12356;&#12398;&#12391;Python&#12398;&#22522;&#26412;&#12387;&#12390;&#20309;&#12384;&#12429;&#12358;&#12392;&#24605;&#12356;&#12388;&#12388;&#12418;pandas, json, datetime, gzip&#12394;&#12393;&#12399;&#20837;&#12428;&#12383;&#12398;&#12391;&#12289;&#35504;&#12363;&#12398;&#21442;&#32771;&#12395;&#12394;&#12428;&#12400;&#24184;&#12356;&#12391;&#12377;&#12290;<\/p><p>&nbsp;<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12863\" src=\"http:\/\/takuminasuno.com\/wp-content\/uploads\/2021\/04\/python.jpg\" alt=\"\" width=\"1600\" height=\"1010\"><\/p><p>&nbsp;<\/p><p>&#12385;&#12394;&#12415;&#12395;&#26132;&#12289;2&#24180;&#21069;&#12367;&#12425;&#12356;&#12395;&#26360;&#12356;&#12390;&#12356;&#12383;&#35352;&#20107;&#12399;&#12371;&#12385;&#12425;&#12391;&#12377;&#12290;&#12372;&#33288;&#21619;&#12354;&#12427;&#26041;&#12399;&#21512;&#12431;&#12379;&#12390;&#12372;&#26619;&#21454;&#12367;&#12384;&#12373;&#12356;&#12290;<\/p><p><a href=\"http:\/\/takuminasuno.com\/ja\/20190612_python_ja\" target=\"_blank\" rel=\"noopener noreferrer\">&#12304;Python&#12487;&#12540;&#12479;&#27963;&#29992;&#12305;CSV&#12501;&#12449;&#12452;&#12523;&#12434;JSON&#12501;&#12449;&#12452;&#12523;&#12289;XML&#12501;&#12449;&#12452;&#12523;&#12395;&#22793;&#25563;&#12375;&#12390;&#20986;&#21147;&#12375;&#12390;&#12415;&#12427;<\/a><\/p><p><a href=\"http:\/\/takuminasuno.com\/ja\/20190603_python_ja\" target=\"_blank\" rel=\"noopener noreferrer\">&#12304;&#20633;&#24536;&#37682;&#12305;Python&#12391;pandas&#12434;&#20351;&#12387;&#12390;Excel&#12501;&#12449;&#12452;&#12523;&#12434;&#35501;&#12415;&#36796;&#12435;&#12391;csv&#12501;&#12449;&#12452;&#12523;&#12434;&#20986;&#21147;&#12377;&#12427;&#12414;&#12391;&#12304;Windows PC&#12305;<\/a><\/p><p>&#12391;&#12399;&#38263;&#12356;&#38263;&#12356;&#26412;&#32232;&#12391;&#12377;&#12290;&#12393;&#12358;&#12382;&#12290;<\/p><p>&nbsp;<\/p><div id=\"ez-toc-container\" class=\"ez-toc-v2_0_68_1 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 \" >\u76ee\u6b21<\/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-4'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/takuminasuno.com\/ja\/20210411_python_ja\/#%E5%9B%9B%E5%89%87%E6%BC%94%E7%AE%97\" title=\"&#22235;&#21063;&#28436;&#31639;\">&#22235;&#21063;&#28436;&#31639;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/takuminasuno.com\/ja\/20210411_python_ja\/#%E6%95%B0%E5%AD%97%E3%81%BE%E3%82%8B%E3%82%81%E3%81%AE%E5%87%A6%E7%90%86\" title=\"&#25968;&#23383;&#12414;&#12427;&#12417;&#12398;&#20966;&#29702;\">&#25968;&#23383;&#12414;&#12427;&#12417;&#12398;&#20966;&#29702;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/takuminasuno.com\/ja\/20210411_python_ja\/#%E6%96%87%E5%AD%97%E5%88%97%E3%81%AE%E5%87%A6%E7%90%86\" title=\"&#25991;&#23383;&#21015;&#12398;&#20966;&#29702;\">&#25991;&#23383;&#21015;&#12398;&#20966;&#29702;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/takuminasuno.com\/ja\/20210411_python_ja\/#%E6%97%A5%E6%99%82%E3%81%AE%E5%87%A6%E7%90%86\" title=\"&#26085;&#26178;&#12398;&#20966;&#29702;\">&#26085;&#26178;&#12398;&#20966;&#29702;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/takuminasuno.com\/ja\/20210411_python_ja\/#%E9%85%8D%E5%88%97%E3%81%AE%E5%87%A6%E7%90%86\" title=\"&#37197;&#21015;&#12398;&#20966;&#29702;\">&#37197;&#21015;&#12398;&#20966;&#29702;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/takuminasuno.com\/ja\/20210411_python_ja\/#%E5%88%86%E5%B2%90%E5%87%A6%E7%90%86\" title=\"&#20998;&#23696;&#20966;&#29702;\">&#20998;&#23696;&#20966;&#29702;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/takuminasuno.com\/ja\/20210411_python_ja\/#%E5%88%86%E5%B2%90%E5%87%A6%E7%90%86%E3%81%AE%E3%81%9F%E3%82%81%E3%81%AEboolean%E5%88%A4%E5%AE%9A%EF%BC%88TrueFalse%E5%88%A4%E5%AE%9A%EF%BC%89\" title=\"&#20998;&#23696;&#20966;&#29702;&#12398;&#12383;&#12417;&#12398;boolean&#21028;&#23450;&#65288;True\/False&#21028;&#23450;&#65289;\">&#20998;&#23696;&#20966;&#29702;&#12398;&#12383;&#12417;&#12398;boolean&#21028;&#23450;&#65288;True\/False&#21028;&#23450;&#65289;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/takuminasuno.com\/ja\/20210411_python_ja\/#%E3%83%AB%E3%83%BC%E3%83%97%E5%87%A6%E7%90%86\" title=\"&#12523;&#12540;&#12503;&#20966;&#29702;\">&#12523;&#12540;&#12503;&#20966;&#29702;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/takuminasuno.com\/ja\/20210411_python_ja\/#JSON%E5%87%A6%E7%90%86\" title=\"JSON&#20966;&#29702;\">JSON&#20966;&#29702;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/takuminasuno.com\/ja\/20210411_python_ja\/#PandasDataframe%E3%81%AE%E5%9F%BA%E6%9C%AC%E5%87%A6%E7%90%86\" title=\"Pandas.Dataframe&#12398;&#22522;&#26412;&#20966;&#29702;\">Pandas.Dataframe&#12398;&#22522;&#26412;&#20966;&#29702;<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/takuminasuno.com\/ja\/20210411_python_ja\/#Pandas%E3%81%AB%E3%82%88%E3%82%8B%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E5%87%A6%E7%90%86\" title=\"Pandas&#12395;&#12424;&#12427;&#12501;&#12449;&#12452;&#12523;&#20966;&#29702;\">Pandas&#12395;&#12424;&#12427;&#12501;&#12449;&#12452;&#12523;&#20966;&#29702;<\/a><\/li><\/ul><\/nav><\/div>\n<h4><span class=\"ez-toc-section\" id=\"%E5%9B%9B%E5%89%87%E6%BC%94%E7%AE%97\"><\/span>&#22235;&#21063;&#28436;&#31639;<span class=\"ez-toc-section-end\"><\/span><\/h4><p>&#19968;&#30058;&#12398;&#30041;&#24847;&#28857;&#12399;&#12289;&#12302;++&#12303;&#12420;&#12302;--&#12303;&#12392;&#12356;&#12387;&#12383;&#12452;&#12531;&#12463;&#12522;&#12513;&#12531;&#12488;&#12364;&#12394;&#12356;&#12371;&#12392;&#12290;<\/p><pre class=\"toolbar:1 lang:python decode:true\">#&#36275;&#12375;&#31639;\r\nprint(11 + 5)\r\n#&#20986;&#21147;&#65306;16\r\n\r\n#&#24341;&#12365;&#31639;\r\nprint(11 - 5)\r\n#&#20986;&#21147;&#65306;6\r\n\r\n#&#25499;&#12369;&#31639;\r\nprint(11 * 5)\r\n#&#20986;&#21147;&#65306;55\r\n\r\n#&#21106;&#12426;&#31639;\r\nprint(11 \/ 5)\r\n#&#20986;&#21147;&#65306;2.2&#12288;&#8251;float&#22411;&#12391;&#36820;&#12373;&#12428;&#12427;\r\n\r\n#&#21106;&#12426;&#31639;&#12398;&#21830;\r\nprint(11 \/\/ 5)\r\n#&#20986;&#21147;&#65306;2&#12288;&#8251;int&#22411;&#12391;&#36820;&#12373;&#12428;&#12427;\r\n\r\n#&#21106;&#12426;&#31639;&#12398;&#20313;&#12426;\r\nprint(11 % 5)\r\n#&#20986;&#21147;&#65306;1&#12288;&#8251;int&#22411;&#12391;&#36820;&#12373;&#12428;&#12427;\r\n\r\n#&#32047;&#20055;\r\nprint(11 ** 5)\r\n#&#20986;&#21147;&#65306;161051\r\n\r\n#&#12452;&#12531;&#12463;&#12522;&#12513;&#12531;&#12488;&#12288;&#8251;Python&#12395;&#12302;++&#12303;&#12399;&#28961;&#12356;\r\na = 1\r\na += 1\r\nprint(a)\r\n#&#20986;&#21147;&#65306;2<\/pre><p>&nbsp;<\/p><h4><span class=\"ez-toc-section\" id=\"%E6%95%B0%E5%AD%97%E3%81%BE%E3%82%8B%E3%82%81%E3%81%AE%E5%87%A6%E7%90%86\"><\/span>&#25968;&#23383;&#12414;&#12427;&#12417;&#12398;&#20966;&#29702;<span class=\"ez-toc-section-end\"><\/span><\/h4><p>&#19968;&#30058;&#12398;&#30041;&#24847;&#28857;&#12399;&#12289;&#12420;&#12399;&#12426;math.round&#12290;&#20182;&#35328;&#35486;&#12392;&#36949;&#12387;&#12390;&#22235;&#25448;&#20116;&#20837;&#12391;&#12399;&#12394;&#12367;&#37504;&#34892;&#20024;&#12417;&#12434;&#25505;&#29992;&#12375;&#12390;&#12356;&#12427;&#12383;&#12417;&#12289;&#21427;&#23494;&#12395;&#22235;&#25448;&#20116;&#20837;&#12434;&#12377;&#12427;&#12395;&#12399;Decimal&#12514;&#12472;&#12517;&#12540;&#12523;&#12434;&#20351;&#12431;&#12394;&#12356;&#12392;&#12356;&#12369;&#12394;&#12356;&#12290;<\/p><pre class=\"toolbar:1 scroll:true lang:python decode:true \">import math\r\nfrom decimal import Decimal, ROUND_HALF_UP, ROUND_CEILING, ROUND_FLOOR\r\n\r\n#&#25972;&#25968;&#12395;&#20999;&#12426;&#25448;&#12390;\r\nprint(math.floor(1.55))\r\n#&#20986;&#21147;&#65306;1\r\n\r\n#&#25972;&#25968;&#12395;&#20999;&#12426;&#25448;&#12390;\r\nprint(int(1.55))\r\n#&#20986;&#21147;&#65306;1\r\n\r\n#&#25972;&#25968;&#12395;&#20999;&#12426;&#19978;&#12370;\r\nprint(math.ceil(1.55))\r\n#&#20986;&#21147;&#65306;2\r\n\r\n#&#25972;&#25968;&#12395;&#22235;&#25448;&#20116;&#20837;\r\nprint(Decimal(str(1.55)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))\r\n#&#20986;&#21147;&#65306;2\r\n#&#12394;&#12362;round&#12399;&#26368;&#12418;&#36817;&#12356;&#20598;&#25968;&#12395;&#20024;&#12417;&#12427;&#12383;&#12417;&#12289;&#22235;&#25448;&#20116;&#20837;&#12391;&#12399;&#12394;&#12356;&#12290;\r\n#&#12394;&#12362;float&#22411;&rarr;decimal&#22411;&#12363;&#12425;&#12398;&#12461;&#12515;&#12473;&#12488;&#26178;&#12398;&#35492;&#24046;&#12434;&#38450;&#12368;&#12383;&#12417;&#12289;&#26377;&#26689;&#23567;&#25968;&#12434;&#20966;&#29702;&#12377;&#12427;&#22580;&#21512;&#12399;&#25991;&#23383;&#21015;&#21270;&#12375;&#12383;&#12354;&#12392;&#12391;decimal&#12395;&#12363;&#12369;&#12427;&#12290;\r\n\r\n#&#23567;&#25968;&#31532;&#19968;&#20301;&#12391;&#20999;&#12426;&#19978;&#12370;\r\nprint(Decimal(str(1.55)).quantize(Decimal('0.1'), rounding=ROUND_CEILING))\r\n#&#20986;&#21147;&#65306;1.6\r\n\r\n#&#23567;&#25968;&#31532;&#19968;&#20301;&#12391;&#20999;&#12426;&#19979;&#12370;\r\nprint(Decimal(str(1.55)).quantize(Decimal('0.1'), rounding=ROUND_FLOOR))\r\n#&#20986;&#21147;&#65306;1.5\r\n\r\n#&#23567;&#25968;&#31532;&#19968;&#20301;&#12391;&#22235;&#25448;&#20116;&#20837;\r\nprint(Decimal(str(1.55)).quantize(Decimal('0.1'), rounding=ROUND_HALF_UP))\r\n#&#20986;&#21147;&#65306;1.6<\/pre><p>&nbsp;<\/p><h4><span class=\"ez-toc-section\" id=\"%E6%96%87%E5%AD%97%E5%88%97%E3%81%AE%E5%87%A6%E7%90%86\"><\/span>&#25991;&#23383;&#21015;&#12398;&#20966;&#29702;<span class=\"ez-toc-section-end\"><\/span><\/h4><p>JavaScript&#12420;PHP&#12395;&#24931;&#12428;&#12390;&#12356;&#12427;&#12392;&#25991;&#23383;&#21015;&#12420;&#25968;&#23383;&#12394;&#12393;&#12398;&#22411;&#12434;&#24847;&#35672;&#12379;&#12378;&#12395;&#32080;&#21512;&#12375;&#12390;&#12375;&#12414;&#12356;&#12364;&#12385;&#12384;&#12364;&#12289;Python&#12391;&#12399;&#32020;&#31883;&#12395;&#25991;&#23383;&#21015;&#21516;&#22763;&#12391;&#32080;&#21512;&#12375;&#12394;&#12356;&#12392;&#12456;&#12521;&#12540;&#12364;&#36215;&#12371;&#12427;&#12290;&#25991;&#23383;&#21015;&#12392;&#25968;&#23383;&#12434;&#32080;&#21512;&#12377;&#12427;&#12399;str&#12391;&#25991;&#23383;&#21015;&#22411;&#12395;&#12461;&#12515;&#12473;&#12488;&#12377;&#12427;&#24517;&#35201;&#12364;&#12354;&#12427;&#28857;&#12399;&#30041;&#24847;&#12398;&#12371;&#12392;&#12290;&#19968;&#26041;&#12398;&#20415;&#21033;&#12394;&#28857;&#12392;&#12375;&#12390;&#12289;&#12473;&#12521;&#12452;&#12473;&#12391;&#38750;&#24120;&#12395;&#27671;&#36605;&#12395;&#25991;&#23383;&#21015;&#12434;&#25277;&#20986;&#12391;&#12365;&#12427;&#28857;&#12364;&#25369;&#12370;&#12425;&#12428;&#12427;&#12290;<\/p><pre class=\"toolbar:1 lang:python decode:true \">import re\r\n\r\n#&#25991;&#23383;&#21015;&#12398;&#32080;&#21512;\r\nprint('a' + 'b')\r\n#&#20986;&#21147;&#65306;ab\r\n\r\n#&#25991;&#23383;&#21015;&#12392;&#25968;&#23383;&#12398;&#32080;&#21512;&#12288;&#8251;str&#12391;&#25991;&#23383;&#21015;&#21270;&#12364;&#24517;&#38920;\r\nprint('a' + str(1))\r\n#&#20986;&#21147;&#65306;a1\r\n\r\n#&#12473;&#12521;&#12452;&#12473;&#12395;&#12390;&#12289;&#26368;&#21021;&#12398;&#25991;&#23383;&#12384;&#12369;&#12434;&#25277;&#20986;\r\nprint('abcde'[0])\r\n#&#20986;&#21147;&#65306;a\r\n\r\n#&#12473;&#12521;&#12452;&#12473;&#12395;&#12390;&#12289;2&#25991;&#23383;&#30446;&#12384;&#12369;&#12434;&#25277;&#20986;\r\nprint('abcde'[1])\r\n#&#20986;&#21147;&#65306;b\r\n\r\n#&#12473;&#12521;&#12452;&#12473;&#12395;&#12390;&#12289;&#26368;&#24460;&#12398;&#25991;&#23383;&#12384;&#12369;&#12434;&#25277;&#20986;\r\nprint('abcde'[-1])\r\n#&#20986;&#21147;&#65306;e\r\n\r\n#&#12473;&#12521;&#12452;&#12473;&#12395;&#12390;&#12289;2&#25991;&#23383;&#30446;&#20197;&#38477;&#12434;&#25277;&#20986;\r\nprint('abcde'[1:])\r\n#&#20986;&#21147;&#65306;bcde\r\n\r\n#&#12473;&#12521;&#12452;&#12473;&#12395;&#12390;&#12289;&#26368;&#24460;&#12363;&#12425;2&#25991;&#23383;&#30446;&#12414;&#12391;&#12434;&#25277;&#20986;\r\nprint('abcde'[:-1])\r\n#&#20986;&#21147;&#65306;abcd\r\n\r\n#&#12473;&#12521;&#12452;&#12473;&#12395;&#12390;&#12289;2&#65374;3&#25991;&#23383;&#30446;&#12398;&#25277;&#20986;\r\nprint('abcde'[1:3])\r\n#&#20986;&#21147;&#65306;bc\r\n\r\n#&#37197;&#21015;&#12398;&#25991;&#23383;&#21015;&#32080;&#21512;&#12288;&#8251;&#12475;&#12497;&#12524;&#12540;&#12479;&#12398;&#12513;&#12477;&#12483;&#12489;&#12394;&#12398;&#12391;&#27880;&#24847;\r\nprint('_'.join(['date','category','name']))\r\n#&#20986;&#21147;&#65306;date_category_name\r\n\r\n#&#29305;&#23450;&#25991;&#23383;&#21015;&#12391;&#37197;&#21015;&#12395;&#20998;&#21106;\r\nprint('date_category_name'.split('_'))\r\n#&#20986;&#21147;&#65306;['date','category','name']\r\n\r\n#&#29305;&#23450;&#25991;&#23383;&#21015;&#12391;&#20998;&#21106;&#12375;&#12383;&#12358;&#12360;&#12391;&#29305;&#23450;&#31623;&#25152;&#12398;&#25277;&#20986;\r\nprint('date_category_name'.split('_')[1])\r\n#&#20986;&#21147;&#65306;category\r\n\r\n#&#25991;&#23383;&#21015;&#22411;&#12398;&#25968;&#23383;&#12434;&#25972;&#25968;&#22411;&#12395;&#12461;&#12515;&#12473;&#12488;&#12377;&#12427;\r\nprint(int('10'))\r\n#&#20986;&#21147;&#65306;10\r\n\r\n#&#25991;&#23383;&#21015;&#22411;&#12398;&#25968;&#23383;&#12434;&#23567;&#25968;&#22411;&#12395;&#12461;&#12515;&#12473;&#12488;&#12377;&#12427;\r\nprint(float('10.5'))\r\n#&#20986;&#21147;&#65306;10.5\r\n\r\n#&#32622;&#25563;&#12501;&#12451;&#12540;&#12523;&#12489;&#12395;&#12424;&#12427;&#25972;&#24418;\r\nprint('Hello {}!'.format('Tom'))\r\n#&#20986;&#21147;&#65306;Hello Tom!\r\n\r\n#&#32622;&#25563;&#12501;&#12451;&#12540;&#12523;&#12489;&#12395;&#12424;&#12427;&#25972;&#24418;&#65288;&#35079;&#25968;&#65289;\r\nprint('This {} is {}!'.format('apple', '$3'))\r\n#&#20986;&#21147;&#65306;This apple is $3!\r\n\r\n#&#32622;&#25563;&#12501;&#12451;&#12540;&#12523;&#12489;&#12395;&#12424;&#12427;&#25972;&#24418;&#65288;&#22793;&#25968;&#21517;&#12434;&#26126;&#31034;&#65289;\r\nprint('This {product} is {price}!'.format(product='apple', price='$3'))\r\n#&#20986;&#21147;&#65306;This apple is $3!\r\n\r\n#&#21336;&#32020;&#12394;&#32622;&#25563;\r\nbuf = '2021-04-05'\r\nprint(buf.replace('-','\/'))\r\n#&#20986;&#21147;&#65306;2021\/04\/05\r\n\r\n#&#27491;&#35215;&#34920;&#29694;&#12398;&#12461;&#12515;&#12503;&#12481;&#12515;&#12464;&#12523;&#12540;&#12503;&#12395;&#12424;&#12427;&#32622;&#25563;\r\nbuf = '20210405'\r\nprint(re.sub(r'(\\d{4})(\\d{2})(\\d{2})', r'\\1\/\\2\/\\3', buf))\r\n#&#20986;&#21147;&#65306;2021\/04\/05<\/pre><p>&nbsp;<\/p><h4><span class=\"ez-toc-section\" id=\"%E6%97%A5%E6%99%82%E3%81%AE%E5%87%A6%E7%90%86\"><\/span>&#26085;&#26178;&#12398;&#20966;&#29702;<span class=\"ez-toc-section-end\"><\/span><\/h4><p>&#19968;&#30058;&#12398;&#30041;&#24847;&#28857;&#12399;&#12289;&#26085;&#12434;&#25201;&#12358;dt.date&#12392;&#26085;&#26178;&#12434;&#25201;&#12358;dt.datetime&#12395;&#23450;&#32681;&#12398;&#27573;&#38542;&#12391;&#20998;&#12363;&#12428;&#12427;&#12371;&#12392;&#12384;&#12429;&#12358;&#12290;&#12513;&#12477;&#12483;&#12489;&#12399;&#12411;&#12412;&#20849;&#36890;&#12391;&#12354;&#12427;&#12364;&#12422;&#12360;&#12395;&#12289;&#20837;&#21475;&#12395;&#12390;&#26126;&#30906;&#12395;&#24847;&#35672;&#12377;&#12427;&#28857;&#12399;&#27671;&#12434;&#20184;&#12369;&#12383;&#12356;&#12290;&#12381;&#12428;&#20197;&#22806;&#12391;&#12356;&#12358;&#12392;&#12289;&#36275;&#12375;&#31639;&#24341;&#12365;&#31639;&#12434;&#12377;&#12427;&#12395;&#12399;relativedelta&#12392;&#12356;&#12358;&#21029;&#12514;&#12472;&#12517;&#12540;&#12523;&#12434;&#20351;&#12358;&#28857;&#12364;&#30452;&#24863;&#30340;&#12394;&#20966;&#29702;&#12391;&#12399;&#12394;&#12356;&#12383;&#12417;&#35226;&#12360;&#12390;&#12362;&#12365;&#12383;&#12356;&#12290;<\/p><pre class=\"toolbar:1 lang:python decode:true\">import datetime as dt\r\nfrom dateutil.relativedelta import relativedelta\r\n#&#8251;&#39006;&#20284;&#12377;&#12427;dt.timedelta&#12391;&#12399;months&#20197;&#19978;&#12364;&#21205;&#12363;&#12394;&#12356;&#27169;&#27096;&#12290;\r\n\r\n#&#26085;&#20184;&#25991;&#23383;&#21015;&#12398;datetime&#22411;&#12408;&#12398;&#12497;&#12540;&#12473;\r\nbuf = '2021\/03\/14 12:15:03'\r\ndate = dt.datetime.strptime(buf,'%Y\/%m\/%d %H:%M:%S')\r\nprint(date)\r\n#&#20986;&#21147;&#65306;2021-03-14 12:15:03\r\n\r\n#&#32716;&#26085;&#12395;&#22793;&#25563;\r\ndate = date + relativedelta(days=1)\r\nprint(date)\r\n#&#20986;&#21147;&#65306;2021-03-15 12:15:03\r\n\r\n#&#25991;&#23383;&#21015;&#12392;&#12375;&#12390;&#26085;&#20184;&#12384;&#12369;&#12501;&#12457;&#12540;&#12510;&#12483;&#12488;&#12377;&#12427;\r\nbuf = dt.datetime.strftime(date,'%Y\/%m\/%d')\r\nprint(buf)\r\n#&#20986;&#21147;&#65306;2021\/03\/15\r\n\r\n#1&#26178;&#38291;&#24460;&#12395;&#22793;&#25563;\r\ndate = date + relativedelta(hours=1)\r\nprint(date)\r\n#&#20986;&#21147;&#65306;2021-03-15 13:15:03\r\n\r\n#30&#20998;&#24460;&#12395;&#22793;&#25563;\r\ndate = date + relativedelta(minutes=30)\r\nprint(date)\r\n#&#20986;&#21147;&#65306;2021-03-15 13:45:03\r\n\r\n#10&#20998;&#24460;&#12395;&#22793;&#25563;\r\ndate = date + relativedelta(seconds=10)\r\nprint(date)\r\n#&#20986;&#21147;&#65306;2021-03-15 13:45:13\r\n\r\n#1&#12534;&#26376;&#24460;&#12395;&#22793;&#25563;\r\ndate = date + relativedelta(months=1)\r\nprint(date)\r\n#&#20986;&#21147;&#65306;2021-04-15 13:45:13\r\n\r\n#1&#24180;&#24460;&#12395;&#22793;&#25563;\r\ndate = date + relativedelta(years=1)\r\nprint(date)\r\n#&#20986;&#21147;&#65306;2022-04-15 13:45:13\r\n\r\n#&#24403;&#26376;&#21021;&#26085;&#12395;&#22793;&#25563;\r\ndate = date.replace(day=1,hour=0,minute=0,second=0)\r\nprint(date)\r\n#&#20986;&#21147;&#65306;2022-04-01 00:00:00\r\n\r\n#&#24403;&#26376;&#26411;&#26085;&#12395;&#22793;&#25563;\r\ndate = date.replace(day=1,hour=0,minute=0,second=0)\r\ndate = date + relativedelta(months=1,days=-1)\r\nprint(date)\r\n#&#20986;&#21147;&#65306;2022-04-30 00:00:00\r\n\r\n#&#24403;&#26085;&#20197;&#38477;&#12398;&#26376;&#26332;&#26085;&#12395;&#22793;&#25563;\r\nw = date.weekday()\r\nincrement = 0 if w == 0 else 7 - w\r\ndate = date + relativedelta(days=increment)\r\nprint(date)\r\n\r\n#&#24403;&#26085;&#20197;&#21069;&#12398;&#27700;&#26332;&#26085;&#12395;&#22793;&#25563;\r\nw = date.weekday()\r\ndecrement = 5 + w if w &lt; 1 else w - 2\r\ndate = date + relativedelta(days=-decrement)\r\nprint(date)<\/pre><p>&nbsp;<\/p><h4><span class=\"ez-toc-section\" id=\"%E9%85%8D%E5%88%97%E3%81%AE%E5%87%A6%E7%90%86\"><\/span>&#37197;&#21015;&#12398;&#20966;&#29702;<span class=\"ez-toc-section-end\"><\/span><\/h4><p>&#25991;&#23383;&#21015;&#12392;&#21516;&#12376;&#12424;&#12358;&#12395;&#12473;&#12521;&#12452;&#12473;&#12364;&#22311;&#20498;&#30340;&#12395;&#20415;&#21033;&#12290;&#12381;&#12428;&#20197;&#22806;&#12391;&#12399;&#12289;lambda&#38306;&#25968;&#12434;&#37197;&#21015;&#12398;&#21508;&#35201;&#32032;&#12395;&#19968;&#25324;&#12391;&#12363;&#12369;&#12427;map&#20966;&#29702;&#12364;&#20415;&#21033;&#12394;&#12398;&#12391;&#12289;map&#12398;&#25147;&#12426;&#20516;&#12364;&#12458;&#12502;&#12472;&#12455;&#12463;&#12488;&#65288;&#12452;&#12486;&#12524;&#12540;&#12479;&#65289;&#12394;&#12398;&#12391;&#12381;&#12398;&#12414;&#12414;for&#12523;&#12540;&#12503;&#12399;&#12391;&#12365;&#12427;&#12364;&#37197;&#21015;&#12392;&#12375;&#12390;&#25201;&#12356;&#12383;&#12356;&#12392;&#12365;&#12399;&#25913;&#12417;&#12390;list&#12395;&#12363;&#12369;&#12427;&#24517;&#35201;&#12364;&#12354;&#12427;&#28857;&#12392;&#19968;&#32210;&#12395;&#38957;&#12395;&#20837;&#12428;&#12390;&#12362;&#12365;&#12383;&#12356;&#12290;<\/p><pre class=\"toolbar:1 scroll:true lang:python decode:true \">#&#29305;&#23450;&#12398;&#20516;&#12434;&#25351;&#23450;&#25968;&#12384;&#12369;&#35201;&#32032;&#12395;&#25345;&#12388;&#37197;&#21015;&#12434;&#29983;&#25104;&#12377;&#12427;\r\nitemList = ['a'] *5\r\nprint(itemList)\r\n#&#20986;&#21147;&#65306;['a', 'a', 'a', 'a', 'a']\r\n\r\n#&#37197;&#21015;&#35201;&#32032;&#12434;&#26411;&#23614;&#12395;&#36861;&#21152;\r\nitemList = ['a','b','c','d','e']\r\nitemList.append('f')\r\nprint(itemList)\r\n#&#20986;&#21147;&#65306;['a','b','c','d','e','f']\r\n\r\n#&#37197;&#21015;&#12392;&#37197;&#21015;&#12434;&#32080;&#21512;\r\nitemList = ['a','b','c','d','e']\r\nitemList.extend(['f','g','h'])\r\nprint(itemList)\r\n#&#20986;&#21147;&#65306;['a','b','c','d','e','f','g','h']\r\n\r\n#&#12473;&#12521;&#12452;&#12473;&#12391;&#37197;&#21015;&#12398;&#38957;&#12434;&#21066;&#38500;\r\nitemList = ['a','b','c','d','e']\r\ndel itemList[0]\r\nprint(itemList)\r\n#&#20986;&#21147;&#65306;['b',c','d','e']\r\n\r\n#&#12473;&#12521;&#12452;&#12473;&#12391;&#37197;&#21015;&#12398;&#26411;&#23614;&#12434;&#21066;&#38500;\r\nitemList = ['a','b','c','d','e']\r\ndel itemList[-1]\r\nprint(itemList)\r\n#&#20986;&#21147;&#65306;['a',b','c',d']\r\n\r\n#&#12473;&#12521;&#12452;&#12473;&#12391;&#37197;&#21015;&#12398;&#25351;&#23450;&#31623;&#25152;&#12434;&#21066;&#38500;\r\nitemList = ['a','b','c','d','e']\r\ndel itemList[1:3]\r\nprint(itemList)\r\n#&#20986;&#21147;&#65306;['a','d',e']\r\n\r\n#&#37197;&#21015;&#12398;&#25351;&#23450;&#20516;&#12434;&#21066;&#38500;\r\nitemList = ['a','b','c','d','e'] \r\nitemList.remove('b')\r\nprint(itemList)\r\n#&#20986;&#21147;&#65306;['a','c',d','e']\r\n\r\n#&#28961;&#21517;&#38306;&#25968;&#65288;lambda&#65289;&#12391;&#37197;&#21015;&#12398;&#20516;&#12434;&#19968;&#25324;&#22793;&#25563;\r\nitemList = ['a','b','c','d','e']\r\nnewitemList = list(map(lambda x : x + '+', itemList))\r\nprint(newitemList)\r\n#&#20986;&#21147;&#65306;['a+', 'b+', 'c+', 'd+', 'e+']\r\n\r\n#&#38306;&#25968;&#12434;&#23450;&#32681;&#12375;&#12383;&#12358;&#12360;&#12391;&#37197;&#21015;&#12398;&#20516;&#12434;&#19968;&#25324;&#22793;&#25563;\r\nitemList = ['a','b','c','d','e']\r\ndef convert(item):\r\n    return item + '+'\r\nnewitemList = list(map(convert, itemList))\r\nprint(newitemList)\r\n#&#20986;&#21147;&#65306;['a+', 'b+', 'c+', 'd+', 'e+']\r\n\r\n#&#37197;&#21015;&#12398;&#20013;&#12391;&#26465;&#20214;&#12395;&#21512;&#33268;&#12377;&#12427;&#12418;&#12398;&#12434;&#25968;&#12360;&#12427;\r\nitemList = ['a','b','c','d','e']\r\naCount = sum(item == 'a' for item in itemList)\r\nprint(aCount)\r\n#&#20986;&#21147;&#65306;1\r\n\r\n#&#37197;&#21015;&#12398;&#20013;&#12391;&#26465;&#20214;&#12395;&#21512;&#33268;&#12377;&#12427;&#12418;&#12398;&#12434;&#25277;&#20986;&#12377;&#12427;\r\nlogList = [\r\n    {'id':'id1','category':'category1'},\r\n    {'id':'id2','category':'category2'},\r\n    {'id':'id3','category':'category1'}\r\n]\r\nlogList = list(filter(lambda x : x['category'] == 'category2', logList))\r\nprint(logList)\r\n#&#20986;&#21147;&#65306;[{'id':'id2','category':'category2'}]\r\n\r\n#&#37197;&#21015;&#12434;&#20006;&#12403;&#26367;&#12360;&#65288;&#37197;&#21015;&#12398;sort&#12513;&#12477;&#12483;&#12489;&#29256;&#65289;\r\nlogList = [\r\n    {'id':'id1','category':'category1'},\r\n    {'id':'id2','category':'category2'},\r\n    {'id':'id3','category':'category1'}\r\n]\r\nlogList.sort(key=lambda x : x['id'], reverse=True)\r\nprint(logList)\r\n#&#20986;&#21147;&#65306;[{'id': 'id3', 'category': 'category1'}, {'id': 'id2', 'category': 'category2'}, {'id': 'id1', 'category': 'category1'}]\r\n\r\n#&#37197;&#21015;&#12434;&#35079;&#25968;&#12461;&#12540;&#12391;&#20006;&#12403;&#26367;&#12360;&#65288;&#37197;&#21015;&#12398;sort&#12513;&#12477;&#12483;&#12489;&#29256;&#65289;\r\nlogList = [\r\n    {'id':'id1','category':'category1'},\r\n    {'id':'id2','category':'category2'},\r\n    {'id':'id3','category':'category1'}\r\n]\r\nlogList.sort(key=lambda x : (x['category'], x['id']), reverse=True)\r\nprint(logList)\r\n#&#20986;&#21147;&#65306;[{'id': 'id2', 'category': 'category2'}, {'id': 'id3', 'category': 'category1'}, {'id': 'id1', 'category': 'category1'}]\r\n\r\n#&#37197;&#21015;&#12434;&#20006;&#12403;&#26367;&#12360;&#65288;&#32068;&#12415;&#36796;&#12415;&#38306;&#25968;&#12398;sorted&#29256;&#65289;\r\nlogList = [\r\n    {'id':'id1','category':'category1'},\r\n    {'id':'id2','category':'category2'},\r\n    {'id':'id3','category':'category1'}\r\n]\r\nlogList = sorted(logList, key=lambda x : x['id'], reverse=True)\r\nprint(logList)\r\n#&#20986;&#21147;&#65306;[{'id': 'id3', 'category': 'category1'}, {'id': 'id2', 'category': 'category2'}, {'id': 'id1', 'category': 'category1'}]<\/pre><p>&nbsp;<\/p><h4><span class=\"ez-toc-section\" id=\"%E5%88%86%E5%B2%90%E5%87%A6%E7%90%86\"><\/span>&#20998;&#23696;&#20966;&#29702;<span class=\"ez-toc-section-end\"><\/span><\/h4><p>&#12302;else if&#12303;&#12398;&#26360;&#12365;&#26041;&#12364;&#12302;elif&#12303;&#12392;&#12356;&#12358;&#38750;&#24120;&#12395;&#29420;&#29305;&#12394;&#26360;&#12365;&#26041;&#12394;&#12398;&#12391;&#27880;&#24847;&#12290;&#19977;&#38917;&#28436;&#31639;&#23376;&#12418;&#12302;{True&#26178;&#12398;&#20516;} if {&#26465;&#20214;} else {False&#26178;&#12398;&#20516;}&#12303;&#12392;&#12394;&#12387;&#12390;&#12356;&#12390;&#12289;&#21475;&#35486;&#30340;&#12394;&#20006;&#12403;&#12391;&#33258;&#28982;&#35328;&#35486;&#12392;&#12375;&#12390;&#35501;&#12415;&#21462;&#12426;&#12420;&#12377;&#12356;&#12418;&#12398;&#12398;&#20182;&#35328;&#35486;&#12392;&#27604;&#12409;&#12427;&#12392;&#29420;&#29305;&#12394;&#12398;&#12391;&#27880;&#24847;&#12375;&#12383;&#12356;&#12290;<\/p><pre class=\"toolbar:1 lang:python decode:true\">#&#22522;&#26412;&#30340;&#12394;if&#12395;&#12424;&#12427;&#20998;&#23696;\r\ndef reply(buf):\r\n    if len(buf) &gt; 4:\r\n        print('4&#25991;&#23383;&#12434;&#36229;&#12360;&#12414;&#12377;')\r\n    elif len(buf) == 4:\r\n        print('4&#25991;&#23383;&#12385;&#12423;&#12358;&#12393;&#12391;&#12377;')\r\n    else:\r\n        print('4&#25991;&#23383;&#26410;&#28288;&#12391;&#12377;')\r\nreply('test')\r\n#&#20986;&#21147;&#65306;4&#25991;&#23383;&#12385;&#12423;&#12358;&#12393;&#12391;&#12377;\r\nreply('testA')\r\n#&#20986;&#21147;&#65306;4&#25991;&#23383;&#12434;&#36229;&#12360;&#12414;&#12377;\r\nreply('tes')\r\n#&#20986;&#21147;&#65306;4&#25991;&#23383;&#26410;&#28288;&#12391;&#12377;\r\n\r\n#&#19977;&#38917;&#28436;&#31639;&#23376;&#12391;if&#12434;1&#34892;&#12391;&#26360;&#12367;\r\ninput = 3\r\nresult = 1 if input == 1 else 0\r\nprint(result)\r\n#&#20986;&#21147;&#65306;0<\/pre><p>&nbsp;<\/p><h4><span class=\"ez-toc-section\" id=\"%E5%88%86%E5%B2%90%E5%87%A6%E7%90%86%E3%81%AE%E3%81%9F%E3%82%81%E3%81%AEboolean%E5%88%A4%E5%AE%9A%EF%BC%88TrueFalse%E5%88%A4%E5%AE%9A%EF%BC%89\"><\/span>&#20998;&#23696;&#20966;&#29702;&#12398;&#12383;&#12417;&#12398;boolean&#21028;&#23450;&#65288;True\/False&#21028;&#23450;&#65289;<span class=\"ez-toc-section-end\"><\/span><\/h4><p>Python&#12399;boolean&#21028;&#23450;&#12364;&#12469;&#12509;&#12540;&#12488;&#12373;&#12428;&#12390;&#12356;&#12390;&#20415;&#21033;&#12394;&#21360;&#35937;&#12290;in&#12395;&#12424;&#12427;&#21253;&#21547;&#21028;&#23450;&#12364;&#12354;&#12427;&#28857;&#12289;&#25968;&#23383;&#12398;&#22823;&#23567;&#38306;&#20418;&#12364;3&#20491;&#20197;&#19978;&#12391;&#12418;&#30452;&#35251;&#30340;&#12395;&#20341;&#35352;&#12391;&#12365;&#12427;&#28857;&#12399;&#12392;&#12367;&#12395;&#20415;&#21033;&#12290;&#12394;&#12362;&#38750;&#24120;&#12395;&#36949;&#21644;&#24863;&#12364;&#12354;&#12427;&#28857;&#12392;&#12375;&#12390;&#12399;&#12289;&#22810;&#35328;&#35486;&#12391;NULL&#12394;&#12393;&#12392;&#21628;&#12400;&#12428;&#12427;&#12302;&#26410;&#23450;&#32681;&#12303;&#12398;&#29366;&#24907;&#12364;&#12302;None&#12303;&#12392;&#21029;&#25991;&#23383;&#12391;&#34920;&#35352;&#12377;&#12427;&#24517;&#35201;&#12364;&#12354;&#12427;&#28857;&#12364;&#25369;&#12370;&#12425;&#12428;&#12427;&#12290;JSON&#24418;&#24335;&#12391;&#12501;&#12449;&#12452;&#12523;&#20986;&#21147;&#12375;&#12383;&#12426;&#12377;&#12427;&#12392;null&#12395;&#22793;&#25563;&#12373;&#12428;&#12427;&#12427;&#12398;&#12391;&#38750;&#24120;&#12395;&#12420;&#12420;&#12371;&#12375;&#12356;&#12290;<\/p><pre class=\"toolbar:1 lang:python decode:true\">#&#25968;&#23383;&#12398;&#22823;&#23567;&#38306;&#20418;&#65288;2&#20491;&#65289;\r\nprint(1 &lt; 2)\r\n#&#20986;&#21147;&#65306;True\r\nprint(1 &gt; 2)\r\n#&#20986;&#21147;&#65306;False\r\n#&#8251;&#12418;&#12385;&#12429;&#12435;&#22823;&#12394;&#12426;&#12452;&#12467;&#12540;&#12523;&#12398;&#22580;&#21512;&#12399;&#12302;&gt;=&#12303;&#12289;&#23567;&#12394;&#12426;&#12452;&#12467;&#12540;&#12523;&#12398;&#22580;&#21512;&#12399;&#12302;&lt;=&#12303;&#12289;&#12494;&#12483;&#12488;&#12452;&#12467;&#12540;&#12523;&#12398;&#22580;&#21512;&#12399;&#12302;!=&#12303;&#12391;&#12354;&#12427;\r\n\r\n#&#25968;&#23383;&#12398;&#22823;&#23567;&#38306;&#20418;&#65288;3&#20491;&#20197;&#19978;&#65289;\r\nprint(1 &lt; 2 &lt; 4)\r\n#&#20986;&#21147;&#65306;True\r\nprint(1 &lt; 2 &lt; 0)\r\n#&#20986;&#21147;&#65306;False\r\n#&#8251;3&#20491;&#20197;&#19978;&#12398;&#22823;&#23567;&#38306;&#20418;&#12434;&#30452;&#35251;&#30340;&#12395;&#20341;&#35352;&#12391;&#12365;&#12427;&#12398;&#12399;Python&#12398;&#29305;&#38263;&#12290;\r\n\r\n#&#29305;&#23450;&#25991;&#23383;&#12434;&#21547;&#12416;&#12363;&#12393;&#12358;&#12363;&#12398;&#21028;&#23450;\r\nprint('e' in 'test')\r\n#&#20986;&#21147;&#65306;True\r\n#&#8251;in&#12398;&#24460;&#12398;&#22793;&#25968;&#12364;NULL&#12398;&#22580;&#21512;&#12399;&#12456;&#12521;&#12540;&#12395;&#12394;&#12427;&#12398;&#12391;&#27880;&#24847;&#12290;\r\n\r\n#&#29305;&#23450;&#25991;&#23383;&#12363;&#12425;&#22987;&#12414;&#12427;&#12363;&#12393;&#12358;&#12363;&#12398;&#21028;&#23450;\r\nprint('test'.startswith('t'))\r\n#&#20986;&#21147;&#65306;True\r\n\r\n#&#29305;&#23450;&#25991;&#23383;&#12391;&#32066;&#12431;&#12427;&#12363;&#12393;&#12358;&#12363;&#12398;&#21028;&#23450;\r\nprint('test'.endswith('t'))\r\n#&#20986;&#21147;&#65306;True\r\n\r\n#NULL&#12363;&#12393;&#12358;&#12363;&#12398;&#21028;&#23450;\r\ntemp = None\r\nprint(temp is None)\r\n#&#20986;&#21147;&#65306;True\r\n\r\n#NULL&#12391;&#12399;&#12394;&#12356;&#12363;&#12393;&#12358;&#12363;&#12398;&#21028;&#23450;\r\ntemp = None\r\nprint(temp is not None)\r\n#&#20986;&#21147;&#65306;False\r\n\r\n#&#37197;&#21015;&#12364;&#29305;&#23450;&#35201;&#32032;&#12434;&#21547;&#12416;&#12363;&#12393;&#12358;&#12363;&#12398;&#21028;&#23450;\r\nvalueList = ['apple','banana','orange']\r\nprint('apple' in valueList)\r\n#&#20986;&#21147;&#65306;True\r\nprint('strawberry' in valueList)\r\n#&#20986;&#21147;&#65306;False\r\n\r\n#&#36899;&#24819;&#37197;&#21015;&#12395;&#29305;&#23450;&#12461;&#12540;&#12364;&#23384;&#22312;&#12377;&#12427;&#12363;&#12393;&#12358;&#12363;&#12398;&#21028;&#23450;\r\nobj = {'id':'id1','date':'2021-03-15','subject':'subjectA','value':10}\r\nprint('date' in obj)\r\n#&#20986;&#21147;&#65306;True\r\nprint('datetime' in obj)\r\n#&#20986;&#21147;&#65306;False\r\nprint(obj.get('date') is not None)\r\n#&#20986;&#21147;&#65306;True\r\nprint(obj.get('datetime') is not None)\r\n#&#20986;&#21147;&#65306;False\r\n#&#8251;&#30452;&#25509;obj['datetime']&#12398;&#12424;&#12358;&#12395;&#21442;&#29031;&#12377;&#12427;&#12392;&#12289;&#12461;&#12540;&#12364;&#23384;&#22312;&#12375;&#12394;&#12356;&#22580;&#21512;&#12395;&#12456;&#12521;&#12540;&#12395;&#12394;&#12427;&#12398;&#12391;&#27880;&#24847;&#12290;\r\n\r\n#&#35079;&#25968;&#26465;&#20214;&#12364;&#20840;&#12390;True&#12391;&#12354;&#12427;&#12363;&#12393;&#12358;&#12363;&#12398;AND&#21028;&#23450;\r\nbuf = 'test'\r\nprint('e' in buf and buf.startswith('t'))\r\n#&#20986;&#21147;&#65306;True\r\nprint('e' in buf and buf.startswith('s'))\r\n#&#20986;&#21147;&#65306;False\r\n\r\n#&#35079;&#25968;&#26465;&#20214;&#12356;&#12378;&#12428;&#12363;&#12364;True&#12391;&#12354;&#12427;&#12363;&#12393;&#12358;&#12363;&#12398;OR&#21028;&#23450;\r\nbuf = 'test'\r\nprint('e' in buf or buf.startswith('t'))\r\n#&#20986;&#21147;&#65306;True\r\nprint('e' in buf or buf.startswith('s'))\r\n#&#20986;&#21147;&#65306;True<\/pre><p>&nbsp;<\/p><h4><span class=\"ez-toc-section\" id=\"%E3%83%AB%E3%83%BC%E3%83%97%E5%87%A6%E7%90%86\"><\/span>&#12523;&#12540;&#12503;&#20966;&#29702;<span class=\"ez-toc-section-end\"><\/span><\/h4><p>&#20182;&#35328;&#35486;&#12391;&#12424;&#12367;&#12354;&#12427;&#12452;&#12531;&#12463;&#12522;&#12513;&#12531;&#12488;&#12395;&#12424;&#12427;for &#12523;&#12540;&#12503;&#12364;&#23384;&#22312;&#12375;&#12394;&#12356;&#12383;&#12417;&#12289;&#12452;&#12531;&#12463;&#12522;&#12513;&#12531;&#12488;&#12434;&#24847;&#35672;&#12375;&#12383;&#12523;&#12540;&#12503;&#12434;&#26360;&#12367;&#12392;&#12365;&#12395;&#12399;enumerate&#12434;&#20351;&#12387;&#12383;&#12426;range&#12434;&#20351;&#12387;&#12383;&#12426;&#12452;&#12531;&#12463;&#12522;&#12513;&#12531;&#12488;&#12434;&#26126;&#31034;&#12375;&#12383;while&#12434;&#20351;&#12387;&#12383;&#12426;&#12394;&#12393;&#24037;&#22827;&#12377;&#12427;&#24517;&#35201;&#12364;&#12354;&#12427;&#12290;&#12394;&#12362;&#12289;&#12381;&#12398;&#12487;&#12513;&#12522;&#12483;&#12488;&#12364;&#27671;&#12395;&#12394;&#12425;&#12394;&#12356;&#12411;&#12393;&#12395;&#12289;&#35201;&#32032;&#12381;&#12398;&#12418;&#12398;&#12434;&#12523;&#12540;&#12503;&#22793;&#25968;&#12395;&#21442;&#29031;&#28193;&#12375;&#12377;&#12427;for&#12523;&#12540;&#12503;&#12399;&#38750;&#24120;&#12395;&#20415;&#21033;&#12394;&#12398;&#12391;&#12289;&#12371;&#12398;&#29305;&#24615;&#12434;&#26377;&#21177;&#27963;&#29992;&#12391;&#12365;&#12427;&#26360;&#12365;&#26041;&#12395;&#23492;&#12379;&#12427;&#12392;&#12356;&#12358;&#12398;&#12364;&#27491;&#25915;&#27861;&#12384;&#12392;&#24863;&#12376;&#12427;&#12290;<\/p><p>&#12383;&#12384;&#12375;&#12289;&#12523;&#12540;&#12503;&#22793;&#25968;&#12395;&#30452;&#25509;&#20195;&#20837;&#12434;&#12377;&#12427;&#12392;&#12300;&#26032;&#12383;&#12395;&#22793;&#25968;&#12364;&#23450;&#32681;&#12373;&#12428;&#12390;&#20803;&#22793;&#25968;&#12399;&#26356;&#26032;&#12373;&#12428;&#12394;&#12356;&#12301;&#12392;&#12356;&#12358;&#32608;&#12399;Python&#12391;&#12418;&#20581;&#22312;&#12394;&#12398;&#12391;&#12289;&#12523;&#12540;&#12503;&#22793;&#25968;&#12434;&#26356;&#26032;&#12377;&#12427;&#21069;&#25552;&#12398;&#26360;&#12365;&#26041;&#12399;&#29305;&#12395;&#27880;&#24847;&#12377;&#12427;&#24517;&#35201;&#12364;&#12354;&#12427;&#12290;<\/p><pre class=\"toolbar:1 lang:python decode:true\">#================================\r\n#&#12288;&#22522;&#26412;\r\n#================================\r\n\r\n#&#37197;&#21015;&#12398;&#12523;&#12540;&#12503;\r\nitemList = ['a','b','c','d','e']\r\nfor item in itemList:\r\n    if item &gt; 'c':\r\n        print(item)\r\n#&#20986;&#21147;&#65306;d\r\n#&#20986;&#21147;&#65306;e\r\n\r\n#&#37197;&#21015;&#12398;&#12523;&#12540;&#12503;&#65288;&#12452;&#12531;&#12487;&#12483;&#12463;&#12473;&#20184;&#12365;&#65289;\r\nitemList = ['a','b','c','d','e']\r\nfor index,item in enumerate(itemList):\r\n    if item &gt; 'c':\r\n        print(index)\r\n#&#20986;&#21147;&#65306;3\r\n#&#20986;&#21147;&#65306;4\r\n\r\n#&#22266;&#23450;&#38263;&#12398;&#12523;&#12540;&#12503;\r\ncount = 0\r\nfor index in range(3):\r\n    count += 1\r\nprint(count)\r\n#&#20986;&#21147;&#65306;3\r\n\r\n#while&#12395;&#12424;&#12427;&#12523;&#12540;&#12503;\r\ncount = 0\r\nwhile True:\r\n    count += 1\r\n    if count &gt; 4:\r\n        break\r\nprint(count)\r\n#&#20986;&#21147;&#65306;5\r\n#while&#12398;&#22580;&#21512;&#12399;&#12452;&#12486;&#12524;&#12540;&#12479;&#22793;&#25968;&#12398;&#22793;&#21270;&#12364;&#26126;&#31034;&#12373;&#12428;&#12394;&#12356;&#12398;&#12391;&#12289;\r\n#&#19981;&#35215;&#21063;&#12394;&#21453;&#24489;&#20966;&#29702;&#12398;&#12358;&#12360;&#12391;&#26465;&#20214;&#21512;&#33268;&#12375;&#12383;&#12425;break&#12377;&#12427;&#22580;&#21512;&#12395;&#25512;&#22888;\r\n\r\n#================================\r\n#&#12288;&#20108;&#37325;&#37197;&#21015;\r\n#================================\r\n\r\n#&#20108;&#37325;&#37197;&#21015;&#12398;&#12523;&#12540;&#12503;\r\ntable = [\r\n    [1,2,3],\r\n    [4,5,6],\r\n    [7,8,9]\r\n]\r\ncount = 0\r\nfor row in table:\r\n    for cell in row:\r\n        count += cell\r\nprint(count)\r\n#&#20986;&#21147;&#65306;45\r\n\r\n#================================\r\n#&#12288;&#36766;&#26360;&#65288;&#36899;&#24819;&#37197;&#21015;&#65289;\r\n#================================\r\n\r\n#&#36766;&#26360;&#12458;&#12502;&#12472;&#12455;&#12463;&#12488;&#65288;dict&#65289;&#12398;&#12523;&#12540;&#12503;\r\ntextMap = {\r\n    'key1':'hello',\r\n    'key2':'world'\r\n}\r\nfor key in textMap:\r\n    print(key)\r\n    print(textMap[key])\r\n#&#20986;&#21147;&#65306;key1\r\n#&#20986;&#21147;&#65306;hello\r\n#&#20986;&#21147;&#65306;key2\r\n#&#20986;&#21147;&#65306;world\r\n\r\n#================================\r\n#&#12288;&#12523;&#12540;&#12503;&#22793;&#25968;&#26356;&#26032;&#12398;&#32771;&#23519;\r\n#================================\r\n\r\n#&#12523;&#12540;&#12503;&#22793;&#25968;&#12399;&#21442;&#29031;&#28193;&#12375;&#12394;&#12398;&#12391;&#12289;\r\n#&#28155;&#12360;&#23383;&#36234;&#12375;&#12391;&#12398;&#20195;&#20837;&#12399;&#20803;&#22793;&#25968;&#12395;&#21453;&#26144;&#12373;&#12428;&#12427;\r\ntable = [\r\n    [1,2,3],\r\n    [4,5,6],\r\n    [7,8,9]\r\n]\r\nfor row in table:\r\n    for iColumn,cell in enumerate(row):\r\n        if cell &gt; 5:\r\n            row[iColumn] = 0\r\nprint(table)\r\n#&#20986;&#21147;&#65306;[[1, 2, 3], [4, 5, 0], [0, 0, 0]]\r\n\r\n#&#12523;&#12540;&#12503;&#22793;&#25968;&#12399;&#21442;&#29031;&#28193;&#12375;&#12384;&#12364;&#12289;\r\n#&#12523;&#12540;&#12503;&#22793;&#25968;&#12408;&#12398;&#30452;&#25509;&#20195;&#20837;&#12399;&#12523;&#12540;&#12503;&#22793;&#25968;&#12364;&#20877;&#23450;&#32681;&#12373;&#12428;&#12427;&#12384;&#12369;&#12391;&#12289;&#20803;&#22793;&#25968;&#12395;&#12399;&#21453;&#26144;&#12373;&#12428;&#12394;&#12356;\r\ntable = [\r\n    [1,2,3],\r\n    [4,5,6],\r\n    [7,8,9]\r\n]\r\nfor row in table:\r\n    for cell in row:\r\n        if cell &gt; 5:\r\n            cell = 0\r\nprint(table)\r\n#&#20986;&#21147;&#65306;[[1, 2, 3], [4, 5, 6], [7, 8, 9]]<\/pre><p>&nbsp;<\/p><h4><span class=\"ez-toc-section\" id=\"JSON%E5%87%A6%E7%90%86\"><\/span>JSON&#20966;&#29702;<span class=\"ez-toc-section-end\"><\/span><\/h4><p>json&#12514;&#12472;&#12517;&#12540;&#12523;&#12434;&#20351;&#12358;&#12392;&#31777;&#21336;&#12395;JSON&#12501;&#12449;&#12452;&#12523;&#12398;&#20837;&#20986;&#21147;&#12364;&#12391;&#12365;&#12427;&#12290;&#12501;&#12449;&#12452;&#12523;&#12363;&#12425;&#25991;&#23383;&#21015;&#12434;&#35501;&#12415;&#36796;&#12416;&#38555;&#12399;&#12289;UTF-8&#12434;&#21069;&#25552;&#12395;&#12375;&#12383;&#12356;&#12290;<\/p><p>&#12394;&#12362;&#12289;json&#12395;&#12399;dumps\/dump&#12289;loads\/load&#12392;&#12356;&#12358;2&#31278;&#39006;&#12398;&#12513;&#12477;&#12483;&#12489;&#12364;&#12354;&#12426;&#12289;&#35079;&#25968;&#24418;&#12392;&#21336;&#25968;&#24418;&#12392;&#12356;&#12358;&#36949;&#12356;&#12395;&#35211;&#12360;&#12427;&#12364;&#12289;&#27231;&#33021;&#30340;&#12395;&#12399;&#12458;&#12502;&#12472;&#12455;&#12463;&#12488;&#12434;&#30452;&#25509;&#28193;&#12377;&#12363;&#25991;&#23383;&#21015;&#12434;&#28193;&#12377;&#12363;&#12398;&#36949;&#12356;&#12364;&#12354;&#12426;&#12289;&#24847;&#22806;&#12392;&#37325;&#35201;&#12290;<\/p><pre class=\"toolbar:1 lang:python decode:true \">import json\r\n\r\nparentPath = 'C:\/Users\/Takumi Nasuno\/Desktop\/'\r\n#&#8251;&#12501;&#12457;&#12523;&#12480;&#12398;&#21306;&#20999;&#12426;&#25991;&#23383;&#12399;&#12302;\\&#12303;&#12391;&#12399;&#12394;&#12367;&#12302;\/&#12303;&#12394;&#12398;&#12391;&#27880;&#24847;&#12290;\r\n\r\ninputData = {\r\n    'hello':'&#12371;&#12435;&#12395;&#12385;&#12399;&#65281;'\r\n}\r\n\r\n#JSON&#12501;&#12449;&#12452;&#12523;&#12392;&#12375;&#12390;&#20986;&#21147;&#65288;&#12356;&#12387;&#12383;&#12435;&#25991;&#23383;&#21015;&#12434;&#20171;&#12377;&#12427;&#20887;&#38263;&#29256;&#65289;\r\nfilePath = parentPath + 'dic.json'\r\nbuf = json.dumps(inputData, ensure_ascii=False)\r\nwith open(filePath,'wt', encoding='UTF-8') as f:\r\n    f.write(buf)\r\n\r\n#JSON&#12501;&#12449;&#12452;&#12523;&#12392;&#12375;&#12390;&#21462;&#12426;&#36796;&#12415;&#65288;&#12356;&#12387;&#12383;&#12435;&#25991;&#23383;&#21015;&#12434;&#20171;&#12377;&#12427;&#20887;&#38263;&#29256;&#65289;\r\nfilePath = parentPath + 'dic.json'\r\nwith open(filePath,'rt', encoding='UTF-8') as f:\r\n    buf = f.read()\r\noutputData = json.loads(buf)\r\nprint(outputData)\r\n#&#20986;&#21147;&#65306;{'hello': '&#12371;&#12435;&#12395;&#12385;&#12399;&#65281;'}\r\n\r\n#JSON&#12501;&#12449;&#12452;&#12523;&#12392;&#12375;&#12390;&#20986;&#21147;&#65288;&#12458;&#12502;&#12472;&#12455;&#12463;&#12488;&#12434;&#30452;&#25509;&#65289;\r\nfilePath = parentPath + 'dic_direct.json'\r\nwith open(filePath,'wt', encoding='UTF-8') as f:\r\n    json.dump(inputData, f, ensure_ascii=False)\r\n\r\n#JSON&#12501;&#12449;&#12452;&#12523;&#12392;&#12375;&#12390;&#21462;&#12426;&#36796;&#12415;&#65288;&#12458;&#12502;&#12472;&#12455;&#12463;&#12488;&#12434;&#30452;&#25509;&#65289;\r\nfilePath = parentPath + 'dic_direct.json'\r\nwith open(filePath,'rt', encoding='UTF-8') as f:\r\n    outputData = json.load(f)\r\nprint(outputData)\r\n#&#20986;&#21147;&#65306;{'hello': '&#12371;&#12435;&#12395;&#12385;&#12399;&#65281;'}<\/pre><p>&nbsp;<\/p><h4><span class=\"ez-toc-section\" id=\"PandasDataframe%E3%81%AE%E5%9F%BA%E6%9C%AC%E5%87%A6%E7%90%86\"><\/span>Pandas.Dataframe&#12398;&#22522;&#26412;&#20966;&#29702;<span class=\"ez-toc-section-end\"><\/span><\/h4><p>pandas&#12434;&#20351;&#12358;&#22580;&#21512;&#12399;&#12289;&#32068;&#12415;&#36796;&#12415;&#38306;&#25968;&#12420;apply&#12434;&#20013;&#24515;&#12392;&#12375;&#12383;&#19968;&#25324;&#22793;&#25563;&#12391;&#12497;&#12501;&#12457;&#12540;&#12510;&#12531;&#12473;&#12364;&#21521;&#19978;&#12377;&#12427;&#12398;&#12391;&#12289;&#19968;&#25324;&#22793;&#25563;&#12434;&#24847;&#35672;&#12375;&#12390;&#27963;&#29992;&#12375;&#12390;&#12356;&#12365;&#12383;&#12356;&#12290;&#34892;&#21015;&#12398;&#12523;&#12540;&#12503;&#12434;&#26360;&#12356;&#12390;&#20491;&#21029;&#12395;&#12523;&#12540;&#12503;&#20966;&#29702;&#12377;&#12427;&#12371;&#12392;&#12418;&#28961;&#29702;&#30690;&#29702;&#12399;&#12391;&#12365;&#12427;&#12364;&#12289;&#21177;&#29575;&#12391;&#12399;&#21155;&#12427;&#12290;&#27880;&#24847;&#28857;&#12392;&#12375;&#12390;&#12289;Excel&#12420;CSV&#12394;&#12393;&#12398;&#22806;&#37096;&#12501;&#12449;&#12452;&#12523;&#12434;&#21462;&#12426;&#36796;&#12435;&#12384;&#12392;&#12365;&#12395;&#31354;&#30333;&#12384;&#12387;&#12383;&#31623;&#25152;&#12399;&#31354;&#30333;&#65288;&#12302;&#12303;&#65289;&#12391;&#12399;&#12394;&#12367;&#12302;NaN&#12303;&#12392;&#12375;&#12390;&#20516;&#12364;&#20837;&#12427;&#12383;&#12417;&#12289;&#12356;&#12431;&#12422;&#12427;NULL&#21028;&#23450;&#12434;pd.isna&#38306;&#25968;&#12391;&#34892;&#12358;&#28857;&#12399;&#30041;&#24847;&#12375;&#12383;&#12356;&#12392;&#12371;&#12429;&#12290;<\/p><pre class=\"toolbar:1 scroll:true lang:python decode:true \">import pandas as pd\r\n\r\n#&#12459;&#12521;&#12512;&#25351;&#23450;&#12391;&#12487;&#12540;&#12479;&#12501;&#12524;&#12540;&#12512;&#12434;&#29983;&#25104;\r\ncolumns = ['id','date','subject','value']\r\ndata = [\r\n    ['id1', '2021-03-15', 'subjectA', 10],\r\n    ['id2', '2021-03-15', 'subjectB', 5],\r\n    ['id3', '2021-03-16', 'subjectB', 12],\r\n    ['id4', '2021-03-17', 'subjectC', -5]\r\n]\r\ndf = pd.DataFrame(data, columns=columns)\r\nprint(df)\r\n#&#20986;&#21147;&#65306;\r\n#   id   date        subject\r\n#0  id1  2021-03-15  subjectA\r\n#1  id2  2021-03-15  subjectB\r\n#2  id3  2021-03-16  subjectB\r\n#3  id4  2021-03-17  subjectC\r\n\r\n#&#29305;&#23450;&#12475;&#12523;&#12364;NULL&#12363;&#12393;&#12358;&#12363;&#12398;&#21028;&#23450;\r\nprint(pd.isna(df['id'][0]))\r\n#&#20986;&#21147;&#65306;False\r\n\r\n#&#34892;&#12398;&#12523;&#12540;&#12503;\r\nsumValue = 0\r\nfor iRow, row in df.iterrows():\r\n    sumValue += row['value']\r\nprint(sumValue)\r\n#&#20986;&#21147;&#65306;22\r\n\r\n#&#21015;&#12398;&#12523;&#12540;&#12503;\r\nbuf = ''\r\nfor iColumn, column in df.iteritems():\r\n    buf += str(column[0])\r\nprint(buf)\r\n#&#20986;&#21147;&#65306;id12021-03-15subjectA10\r\n\r\n#&#34892;&#21015;&#12398;&#12523;&#12540;&#12503;\r\nbuf = ''\r\nfor iRow, row in df.iterrows():\r\n    for iColumn, column in df.iteritems():\r\n        buf += str(row[iColumn])\r\nprint(buf)\r\n#&#20986;&#21147;&#65306;id12021-03-15subjectA10id22021-03-15subjectB5id32021-03-16subjectB12id42021-03-17subjectC-5\r\n#&#12475;&#12523;&#12434;&#21442;&#29031;&#12377;&#12427;&#12392;&#12365;&#12395;row&#12395;&#23550;&#12375;&#12390;iColumn&#12391;&#21462;&#24471;&#12377;&#12427;&#12398;&#12364;&#12467;&#12484;&#12290;\r\n\r\n#apply lambda&#12395;&#12424;&#12427;&#25351;&#23450;&#21015;&#12398;&#19968;&#25324;&#22793;&#25563;\r\ndf['subject'] = df['subject'].apply(lambda x : x.replace('subject','&#34920;&#38988;'))\r\nprint(df)\r\n#&#20986;&#21147;&#65306;\r\n#    id        date subject  value\r\n#0  id1  2021-03-15     &#34920;&#38988;A     10\r\n#1  id2  2021-03-15     &#34920;&#38988;B      5\r\n#2  id3  2021-03-16     &#34920;&#38988;B     12\r\n#3  id4  2021-03-17     &#34920;&#38988;C     -5\r\n\r\n#&#12394;&#12362;&#12289;lambda&#12434;&#22793;&#25968;&#12395;&#26684;&#32013;&#12377;&#12427;&#12371;&#12392;&#12418;&#21487;\r\nupdateSubject = lambda x : x.replace('&#34920;&#38988;','subject')\r\ndf['subject'] = df['subject'].apply(updateSubject)\r\nprint(df)\r\n#&#20986;&#21147;&#65306;\r\n#    id        date subject  value\r\n#0  id1  2021-03-15     subjectA     10\r\n#1  id2  2021-03-15     subjectB      5\r\n#2  id3  2021-03-16     subjectB     12\r\n#3  id4  2021-03-17     subjectC     -5\r\n\r\n#&#12394;&#12362;&#12289;def&#38306;&#25968;&#12391;&#12418;&#26360;&#12369;&#12427;\r\ndef updateValue(number):\r\n    return number * 2\r\ndf['value'] = df['value'].apply(updateValue)\r\nprint(df)\r\n#&#20986;&#21147;&#65306;\r\n#    id        date subject  value\r\n#0  id1  2021-03-15     subjectA     20\r\n#1  id2  2021-03-15     subjectB     10\r\n#2  id3  2021-03-16     subjectB     24\r\n#3  id4  2021-03-17     subjectC    -10\r\n\r\n#&#29305;&#23450;&#21015;&#12398;&#20516;&#12395;&#12424;&#12427;&#34892;&#12501;&#12451;&#12523;&#12479;&#12540;&#65288;index&#12399;&#12381;&#12398;&#12414;&#12414;&#12392;&#12394;&#12427;&#12398;&#12391;&#30041;&#24847;&#65289;\r\nfilteredDf = df.query('date &gt; \"2021-03-16\"')\r\nprint(filteredDf)\r\n#&#20986;&#21147;&#65306;\r\n#    id        date   subject  value\r\n#3  id4  2021-03-17  subjectC    -10<\/pre><p>&nbsp;<\/p><h4><span class=\"ez-toc-section\" id=\"Pandas%E3%81%AB%E3%82%88%E3%82%8B%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E5%87%A6%E7%90%86\"><\/span>Pandas&#12395;&#12424;&#12427;&#12501;&#12449;&#12452;&#12523;&#20966;&#29702;<span class=\"ez-toc-section-end\"><\/span><\/h4><p>&#12501;&#12449;&#12452;&#12523;&#20966;&#29702;&#12391;&#27671;&#12434;&#20184;&#12369;&#12383;&#12356;&#12418;&#12398;&#12490;&#12531;&#12496;&#12540;&#12527;&#12531;&#12399;&#12289;&#12392;&#12367;&#12363;&#12367;&#12456;&#12531;&#12467;&#12540;&#12489;&#12290;UTF-8&#12434;&#21069;&#25552;&#12392;&#12375;&#12383;&#20966;&#29702;&#12395;Shift_JIS&#12392;&#12356;&#12358;&#24746;&#12375;&#12365;&#32722;&#24931;&#12364;&#32027;&#12428;&#12390;&#20966;&#29702;&#12364;&#22238;&#12425;&#12394;&#12356;&#12392;&#12356;&#12358;&#12452;&#12540;&#12472;&#12540;&#12511;&#12473;&#12399;&#36991;&#12369;&#12383;&#12356;&#12375;&#12289;UTF-8&#12395;&#12375;&#12390;&#12418;Unicode&#12456;&#12473;&#12465;&#12540;&#12503;&#12377;&#12427;&#12398;&#12363;&#12375;&#12394;&#12356;&#12398;&#12363;&#12399;&#26126;&#31034;&#30340;&#12395;&#26360;&#12365;&#12383;&#12356;&#12290;&#12414;&#12383;&#12289;&#23455;&#21209;&#19978;&#12399;gzip&#22311;&#32302;&#12375;&#12390;&#12398;&#31649;&#29702;&#12364;&#12424;&#12367;&#20986;&#12390;&#12367;&#12427;&#12383;&#12417;&#12289;&#22311;&#32302;&#24418;&#24335;&#12392;&#12375;&#12390;&#12398;gzip&#12398;&#20966;&#29702;&#12418;&#37325;&#35201;&#12290;<\/p><pre class=\"toolbar:1 scroll:true lang:python decode:true\">import pandas as pd\r\nimport gzip\r\n\r\nparentPath = 'C:\/Users\/Takumi Nasuno\/Desktop\/'\r\n#&#8251;&#12501;&#12457;&#12523;&#12480;&#12398;&#21306;&#20999;&#12426;&#25991;&#23383;&#12399;&#12302;\\&#12303;&#12391;&#12399;&#12394;&#12367;&#12302;\/&#12303;&#12394;&#12398;&#12391;&#27880;&#24847;&#12290;\r\n\r\n#================================\r\n#&#12288;&#12469;&#12531;&#12503;&#12523;&#12487;&#12540;&#12479;&#12398;&#29983;&#25104;\r\n#================================\r\n\r\ncolumns = ['&#21015;A','&#21015;B','&#21015;C']\r\ndata = [\r\n    [1,2,3],\r\n    [4,5,6],\r\n    [7,8,9]\r\n]\r\ndf = pd.DataFrame(data, columns=columns)\r\n\r\n#================================\r\n#&#12288;output&#22522;&#26412;\r\n#================================\r\n\r\n#&#9660;CSV&#32232;\r\n#df.to_csv&#12398;&#12456;&#12531;&#12467;&#12540;&#12489;&#12399;UTF-8&#12364;&#12487;&#12501;&#12457;&#12523;&#12488;\r\n\r\n#&#12487;&#12501;&#12457;&#12523;&#12488;&#12398;UTF-8&#12395;&#12390;CSV&#20986;&#21147;\r\nfilePath = parentPath + 'output_utf8.csv'\r\ndf.to_csv(filePath, index=False)\r\n\r\n#Shift_JIS&#12434;&#26126;&#31034;&#30340;&#12395;&#25351;&#23450;&#12375;&#12390;&#12289;CSV&#20986;&#21147;\r\nfilePath = parentPath + 'output_shiftjis.csv'\r\ndf.to_csv(filePath, index=False, encoding='Shift_JIS')\r\n\r\n#&#9660;JSON&#32232;\r\n#df.to_json&#12398;&#12456;&#12531;&#12467;&#12540;&#12489;&#12399;OS&#12398;&#12471;&#12473;&#12486;&#12512;&#12525;&#12465;&#12540;&#12523;&#12395;&#24467;&#12358;&#12398;&#12391;&#12289;\r\n#Windows&#12398;&#22580;&#21512;&#12399;&#12471;&#12473;&#12486;&#12512;&#12525;&#12465;&#12540;&#12523;&#12395;&#12390;&#12302;&#12505;&#12540;&#12479;&#65306;&#12527;&#12540;&#12523;&#12489;&#12527;&#12452;&#12489;&#35328;&#35486;&#12391; Unicode UTF-8 &#12434;&#20351;&#29992;&#12303;&#12395;&#12481;&#12455;&#12483;&#12463;&#12434;&#20837;&#12428;&#12427;&#12363;&#12289;\r\n#&#24460;&#36848;&#12377;&#12427;&#26126;&#31034;&#30340;&#12394;&#20966;&#29702;&#12434;&#12375;&#12394;&#12356;&#12392;Shift_JIS&#12395;&#12394;&#12387;&#12390;&#12356;&#12427;&#12371;&#12392;&#12364;&#22810;&#12356;&#12398;&#12391;&#27880;&#24847;&#12290;\r\n\r\n#JSON&#20986;&#21147;&#65288;&#21508;&#34892;&#12434;&#35201;&#32032;&#12392;&#12375;&#12383;&#37197;&#21015;&#65289;\r\nfilePath = parentPath + 'output.json'\r\ndf.to_json(filePath, orient='records', force_ascii=False)\r\n\r\n#JSONLines&#24418;&#24335;&#12391;&#12398;&#20986;&#21147;&#65288;&#21508;&#34892;&#12434;&#29420;&#31435;&#12375;&#12383;JSON&#12392;&#12375;&#12390;&#25913;&#34892;&#21306;&#20999;&#12426;&#12395;&#12375;&#12383;&#12418;&#12398;&#65289;\r\nfilePath = parentPath + 'output.jsonl'\r\ndf.to_json(filePath, orient='records', force_ascii=False, lines=True)\r\n\r\n#UTF-8&#12434;&#26126;&#31034;&#12375;&#12390;&#12289;JSON&#24418;&#24335;&#12391;&#12398;&#20986;&#21147;\r\nfilePath = parentPath + 'output_uft8.json'\r\nbuf = df.to_json(orient='records', force_ascii=False)\r\nwith open(filePath,'wt', encoding='UTF-8') as f:\r\n    f.write(buf)\r\n\r\n#UTF-8&#12434;&#26126;&#31034;&#12375;&#12390;&#12289;JSONLines&#24418;&#24335;&#12391;&#12398;&#20986;&#21147;\r\nfilePath = parentPath + 'output_uft8.jsonl'\r\nbuf = df.to_json(orient='records', force_ascii=False, lines=True)\r\nwith open(filePath,'wt', encoding='UTF-8') as f:\r\n    f.write(buf)\r\n\r\n#&#9660;Excel&#32232;\r\n\r\n#Excel&#12501;&#12449;&#12452;&#12523;&#12392;&#12375;&#12390;&#20986;&#21147;\r\nfilePath = parentPath + 'output.xlsx'\r\ndf.to_excel(filePath, sheet_name='Sheet1', index=False)\r\n\r\n#================================\r\n#&#12288;input&#22522;&#26412;\r\n#================================\r\n\r\n#&#9660;CSV&#32232;\r\n\r\n#CSV&#12501;&#12449;&#12452;&#12523;(Shift_JIS)&#12398;&#21462;&#12426;&#36796;&#12415;\r\nfilePath = parentPath + 'output_shiftjis.csv'\r\ndf = pd.read_csv(filePath, encoding='Shift_JIS')\r\n\r\n#CSV&#12501;&#12449;&#12452;&#12523;(UTF-8)&#12398;&#21462;&#12426;&#36796;&#12415;\r\nfilePath = parentPath + 'output_utf8.csv'\r\ndf = pd.read_csv(filePath, encoding='UTF-8')\r\n\r\n#&#9660;JSON&#32232;\r\n\r\n#JSON&#12501;&#12449;&#12452;&#12523;&#65288;UTF-8&#65289;&#12398;&#21462;&#12426;&#36796;&#12415;\r\nfilePath = parentPath + 'output_uft8.json'\r\ndf = pd.read_json(filePath, orient='records', encoding='UTF-8')\r\n\r\n#JSONLines&#12501;&#12449;&#12452;&#12523;&#65288;UTF-8&#65289;&#12398;&#21462;&#12426;&#36796;&#12415;\r\nfilePath = parentPath + 'output_uft8.jsonl'\r\ndf = pd.read_json(filePath, orient='records', encoding='UTF-8', lines=True)\r\n\r\n#&#9660;Excel&#32232;\r\n\r\n#Excel&#12398;&#12471;&#12540;&#12488;&#21517;&#19968;&#35239;&#12398;&#21462;&#24471;\r\nfilePath = parentPath + 'output.xlsx'\r\nsheetNameList = pd.ExcelFile(filePath).sheet_names\r\nprint(sheetNameList)\r\n#&#20986;&#21147;&#65306;['Sheet1']\r\n\r\n#Excel&#12471;&#12540;&#12488;&#12398;&#21462;&#12426;&#36796;&#12415;&#65288;&#12504;&#12483;&#12480;&#12540;&#12354;&#12426;&#65289;\r\nfilePath = parentPath + 'output.xlsx'\r\nsheetName = 'Sheet1'\r\ndf = pd.read_excel(filePath, sheet_name=sheetName)\r\nprint(df)\r\n#&#20986;&#21147;\r\n#   &#21015;A  &#21015;B  &#21015;C\r\n#0   1   2   3\r\n#1   4   5   6\r\n#2   7   8   9\r\n\r\n#Excel&#12471;&#12540;&#12488;&#12398;&#21462;&#12426;&#36796;&#12415;&#65288;&#12504;&#12483;&#12480;&#12540;&#12394;&#12375;&#12391;1&#34892;&#30446;&#12434;&#12473;&#12461;&#12483;&#12503;&#65289;\r\nfilePath = parentPath + 'output.xlsx'\r\nsheetName = 'Sheet1'\r\ndf = pd.read_excel(filePath, sheet_name=sheetName, header=None, skiprows=1)\r\nprint(df)\r\n#&#20986;&#21147;\r\n#   0  1  2\r\n#0  1  2  3\r\n#1  4  5  6\r\n#2  7  8  9\r\n\r\n#&#12459;&#12521;&#12512;&#21517;&#65288;&#12504;&#12483;&#12480;&#12540;&#65289;&#12398;&#19978;&#26360;&#12365;\r\ncolumns = ['colA', 'colB', 'colC']\r\ndf.set_axis(columns, axis='columns', inplace=True)\r\nprint(df)\r\n#&#20986;&#21147;\r\n#   colA  colB  colC\r\n#0     1     2     3\r\n#1     4     5     6\r\n#2     7     8     9\r\n\r\n#================================\r\n#&#12288;&#24540;&#29992;&#12398;gzip&#22311;&#32302;\r\n#================================\r\n\r\n#&#24858;&#30452;&#12395;gzip&#12514;&#12472;&#12517;&#12540;&#12523;&#12434;&#20351;&#12387;&#12390;&#12289;JSONLines&#12501;&#12449;&#12452;&#12523;&#12434;&#20445;&#23384;\r\nfilePath = parentPath + 'output.jsonl.gz'\r\nbuf  = df.to_json(orient='records', force_ascii=False, lines=True)\r\nwith gzip.open(filePath, 'wt', encoding='UTF-8') as f:\r\n    f.write(buf)\r\n#&#8251;to_json&#12395;&#12390;&#12501;&#12449;&#12452;&#12523;&#21517;&#12434;&#25351;&#23450;&#12379;&#12378;&#12289;&#25991;&#23383;&#21015;&#12392;&#12375;&#12390;&#25147;&#12375;&#12390;gzip.open.write&#12395;&#28193;&#12377;&#12398;&#12364;&#12509;&#12452;&#12531;&#12488;&#12290;\r\n\r\n#&#24858;&#30452;&#12395;gzip&#12514;&#12472;&#12517;&#12540;&#12523;&#12434;&#20351;&#12387;&#12390;&#12289;JSONLines&#12501;&#12449;&#12452;&#12523;&#12398;&#21462;&#12426;&#36796;&#12415;\r\nfilePath = parentPath + 'output.jsonl.gz'\r\nwith gzip.open(filePath, 'rt', encoding='UTF-8') as f:\r\n    buf = f.read()\r\ndf = pd.read_json(buf, orient='records', encoding='UTF-8', lines=True)\r\n\r\n#df.to_json&#12398;&#12458;&#12503;&#12471;&#12519;&#12531;&#12391;compression='gzip'&#12434;&#25351;&#23450;&#12375;&#12390;&#12289;JSONLines&#12501;&#12449;&#12452;&#12523;&#12434;&#20445;&#23384;\r\nfilePath = parentPath + 'output_direct.jsonl.gz'\r\ndf.to_json(filePath,orient='records', force_ascii=False, lines=True, compression='gzip')\r\n\r\n#df.read_json&#12398;&#12458;&#12503;&#12471;&#12519;&#12531;&#12391;compression='gzip'&#12434;&#25351;&#23450;&#12375;&#12390;&#12289;JSONLines&#12501;&#12449;&#12452;&#12523;&#12398;&#21462;&#12426;&#36796;&#12415;\r\nfilePath = parentPath + 'output_direct.jsonl.gz'\r\ndf = pd.read_json(filePath, orient='records', encoding='UTF-8', lines=True, compression='gzip')<\/pre><p>&nbsp;<\/p><p>&#20197;&#19978;&#12289;&#12374;&#12387;&#12367;&#12426;&#12375;&#12383;&#12414;&#12392;&#12417;&#12391;&#12375;&#12383;&#12290;&#12503;&#12525;&#12464;&#12521;&#12511;&#12531;&#12464;&#12398;&#19990;&#30028;&#12399;&#26085;&#12293;&#21193;&#24375;&#12391;&#12377;&#12397;&#12290;<\/p><p>&#27491;&#30452;&#12394;&#12392;&#12371;&#12429;&#12289;Python&#12398;&#29305;&#38263;&#12399;&#12514;&#12472;&#12517;&#12540;&#12523;&#65288;&#12521;&#12452;&#12502;&#12521;&#12522;&#65289;&#12398;&#35914;&#23500;&#12373;&#12395;&#12354;&#12427;&#12398;&#12391;&#12289;&#12371;&#12358;&#12356;&#12387;&#12383;&#22522;&#26412;&#30340;&#12394;&#20966;&#29702;&#12384;&#12369;&#12391;&#12354;&#12428;&#12400;Go&#12391;&#26360;&#12356;&#12383;&#26041;&#12364;&#12497;&#12501;&#12457;&#12540;&#12510;&#12531;&#12473;&#12364;&#22823;&#12365;&#12367;&#21521;&#19978;&#12377;&#12427;&#12392;&#24605;&#12358;&#12392;Go&#12391;&#26360;&#12356;&#12383;&#26041;&#12364;&#12356;&#12356;&#12435;&#12376;&#12419;&#12394;&#12356;&#12363;&#12392;&#24605;&#12356;&#12388;&#12388;&#12418;&#12289;&#12510;&#12540;&#12465;&#12483;&#12488;&#30340;&#12395;Python&#20154;&#26448;&#12424;&#12426;&#12418;Go&#20154;&#26448;&#12398;&#26041;&#12364;&#22311;&#20498;&#30340;&#12395;&#23569;&#12394;&#12356;&#12358;&#12360;&#12395;&#23398;&#32722;&#12467;&#12473;&#12488;&#12418;&#39640;&#12356;&#12371;&#12392;&#12434;&#32771;&#12360;&#12427;&#12392;&#12499;&#12472;&#12493;&#12473;&#30340;&#12395;&#12399;&#38750;&#24120;&#12395;&#38627;&#12375;&#12356;&#21028;&#26029;&#12393;&#12371;&#12429;&#12394;&#12435;&#12384;&#12429;&#12358;&#12394;&#12392;&#24605;&#12358;&#20170;&#26085;&#12371;&#12398;&#38915;&#12391;&#12377;&#12290;<\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#12371;&#12435;&#12395;&#12435;&#12385;&#12399;&#12290;&#37027;&#38920;&#37326;&#12391;&#12377;&#12290;Python [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":12870,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[252],"tags":[],"class_list":["post-12861","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-business_ja"],"_links":{"self":[{"href":"https:\/\/takuminasuno.com\/ja\/wp-json\/wp\/v2\/posts\/12861","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/takuminasuno.com\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/takuminasuno.com\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/takuminasuno.com\/ja\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/takuminasuno.com\/ja\/wp-json\/wp\/v2\/comments?post=12861"}],"version-history":[{"count":14,"href":"https:\/\/takuminasuno.com\/ja\/wp-json\/wp\/v2\/posts\/12861\/revisions"}],"predecessor-version":[{"id":12893,"href":"https:\/\/takuminasuno.com\/ja\/wp-json\/wp\/v2\/posts\/12861\/revisions\/12893"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/takuminasuno.com\/ja\/wp-json\/wp\/v2\/media\/12870"}],"wp:attachment":[{"href":"https:\/\/takuminasuno.com\/ja\/wp-json\/wp\/v2\/media?parent=12861"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/takuminasuno.com\/ja\/wp-json\/wp\/v2\/categories?post=12861"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/takuminasuno.com\/ja\/wp-json\/wp\/v2\/tags?post=12861"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}