{"id":152,"date":"2019-11-15T16:22:15","date_gmt":"2019-11-15T07:22:15","guid":{"rendered":"http:\/\/aiacademy.jp\/media\/?p=152"},"modified":"2025-06-06T14:35:35","modified_gmt":"2025-06-06T05:35:35","slug":"%e3%80%90%e5%88%9d%e5%bf%83%e8%80%85%e5%90%91%e3%81%91%e3%80%91%e3%83%87%e3%83%bc%e3%82%bf%e5%88%86%e6%9e%90%e3%81%a7%e5%bf%85%e9%a0%88%e3%81%aepandas%e3%82%92%e5%85%a5%e9%96%80%e3%81%97%e3%82%88","status":"publish","type":"post","link":"https:\/\/aiacademy.jp\/media\/?p=152","title":{"rendered":"\u3010\u521d\u5fc3\u8005\u5411\u3051\u3011\u30c7\u30fc\u30bf\u5206\u6790\u3067\u5fc5\u9808\u306ePandas\u3092\u5165\u9580\u3057\u3088\u3046\uff01"},"content":{"rendered":"<div class=\"toc\">    <div id=\"toc_container\" class=\"sgb-toc--no-bullets js-smooth-scroll\" data-dialog-title=\"Table of Contents\">\n      <p class=\"toc_title\">\u76ee\u6b21 <\/p>\n      <ul class=\"toc_list\">  <li class=\"first\">    <a href=\"#i-0\">Pandas\u3068\u306f<\/a>  <\/li>  <li>    <a href=\"#i-1\">\u306a\u305cPandas\u3092\u5b66\u3076\u306e\u304b<\/a>  <\/li>  <li>    <a href=\"#i-2\">Pandas\u3092\u4f7f\u3046\u30e1\u30ea\u30c3\u30c8<\/a>  <\/li>  <li>    <a href=\"#i-3\">Pandas\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/a>  <\/li>  <li>    <a href=\"#i-4\"><\/a>  <\/li>  <li>    <a href=\"#i-5\"><\/a>  <\/li>  <li>    <a href=\"#i-6\">Pandas\u3092\u4f7f\u3046<\/a>  <\/li>  <li>    <a href=\"#i-7\">\u30c7\u30fc\u30bf\u578b(pandas\u306e\u57fa\u672c\u30c7\u30fc\u30bf\u578b)<\/a>  <\/li>  <li>    <a href=\"#i-8\">\u30b7\u30ea\u30fc\u30ba<\/a>  <\/li>  <li>    <a href=\"#i-9\">\u3010\u7121\u6599\u52d5\u753b\uff1a\u500d\u901f\u3067\u5b66\u3076\uff01\u751f\u6210AI\u3092\u6d3b\u7528\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u52c9\u5f37\u6cd5\uff08\u77ed\u7e2e\u7248\uff09\u3011<\/a>  <\/li>  <li>    <a href=\"#i-10\">head()\u3068tail()<\/a>  <\/li>  <li>    <a href=\"#i-11\">loc\u3068iloc<\/a>  <\/li>  <li>    <a href=\"#i-12\">\u6761\u4ef6\u306b\u3088\u308b\u884c\u306e\u62bd\u51fa(query)<\/a>  <\/li>  <li>    <a href=\"#i-13\">\u30c7\u30fc\u30bf\u306e\u5165\u51fa\u529b<\/a>  <\/li>  <li>    <a href=\"#i-14\">Pandas \u30bd\u30fc\u30c8<\/a>  <\/li>  <li>    <a href=\"#i-15\">\u6b20\u640d\u5024\u306e\u51e6\u7406<\/a>  <\/li>  <li>    <a href=\"#i-16\">\u307e\u3068\u3081<\/a>  <\/li>  <li>    <a href=\"#i-17\">\u6f14\u7fd2\u554f\u984c<\/a>  <\/li>  <li>    <a href=\"#i-18\">Pandas\u3092\u306f\u3058\u3081\u3066\u5b66\u3076\u3042\u306a\u305f\u3078\uff1a\u3088\u304f\u3042\u308b\u8cea\u554f\u3068\u56de\u7b54<\/a>  <\/li>  <li class=\"last\">    <a href=\"#i-19\">\u2728AI\u4eba\u6750\u30b3\u30fc\u30b9 \u53d7\u8b1b\u304a\u7533\u8fbc\u307f\u53d7\u4ed8\u4e2d\uff01\u00a0<\/a>  <\/li><\/ul>\n      \n    <\/div><\/div><div class=\"toc\"><p><\/p>\n<\/div><h2 id=\"i-0\">Pandas\u3068\u306f<\/h2>\n<p><strong><em><a href=\"https:\/\/pandas.pydata.org\/\" rel=\"nofollow noopener\" target=\"_blank\">Pandas(\u30d1\u30f3\u30c0\u30b9)<\/a>\u3068\u306f\u3001\u30c7\u30fc\u30bf\u89e3\u6790\u3092\u5bb9\u6613\u306b\u3059\u308b\u6a5f\u80fd\u3092\u63d0\u4f9b\u3059\u308bPython\u306e\u30c7\u30fc\u30bf\u89e3\u6790\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002<\/em><\/strong><br>Pandas\u306e\u7279\u5fb4\u306b\u306f\u3001\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0(DataFrame)\u306a\u3069\u306e\u72ec\u81ea\u306e\u30c7\u30fc\u30bf\u69cb\u9020\u304c\u63d0\u4f9b\u3055\u308c\u3066\u304a\u308a\u3001\u69d8\u3005\u306a\u51e6\u7406\u304c\u53ef\u80fd\u3067\u3059\u3002<br>\u7279\u306b\u3001\u8868\u5f62\u5f0f\u306e\u30c7\u30fc\u30bf\u3092<a href=\"https:\/\/aiacademy.jp\/texts\/#sql\">SQL<\/a>\u307e\u305f\u306f<a href=\"https:\/\/aiacademy.jp\/texts\/#r\">R<\/a>\u306e\u3088\u3046\u306b\u64cd\u4f5c\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3001\u304b\u3064\u9ad8\u901f\u3067\u51e6\u7406\u51fa\u6765\u307e\u3059\u3002<br>\u6700\u65b0\u60c5\u5831\u306b\u95a2\u3057\u3066\u306f <a href=\"http:\/\/pandas.pydata.org\/\" rel=\"nofollow noopener\" target=\"_blank\">\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8<\/a>\u3092\u53c2\u8003\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<p><span class=\"keiko_blue keiko_green\">\u3053\u306e\u30b5\u30a4\u30c8\u306f\u3001Python\u3084\u751f\u6210AI\u306a\u3069\u3092\u5b66\u3079\u308b\u30aa\u30f3\u30e9\u30a4\u30f3\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u30b9\u30af\u30fc\u30eb AI Academy Bootcamp\u304c\u904b\u55b6\u3057\u3066\u3044\u307e\u3059\u3002<\/span><\/p>\n<p>Pandas\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001\u4e0b\u8a18\u306e\u3088\u3046\u306a\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n<blockquote>\n<p>CSV\u3084Excel\u3001RDB\u306a\u3069\u306b\u30c7\u30fc\u30bf\u3092\u5165\u51fa\u529b\u3067\u304d\u308b<br>\u30c7\u30fc\u30bf\u524d\u51e6\u7406(NaN \/ Not a Number\u3001\u6b20\u640d\u5024)<br>\u30c7\u30fc\u30bf\u306e\u7d50\u5408\u3084\u90e8\u5206\u7684\u306a\u53d6\u308a\u51fa\u3057\u3084\u30d4\u30dc\u30c3\u30c9(pivot)\u51e6\u7406<br>\u30c7\u30fc\u30bf\u306e\u96c6\u7d04\u53ca\u3073\u30b0\u30eb\u30fc\u30d7\u6f14\u7b97<br>\u30c7\u30fc\u30bf\u306b\u5bfe\u3057\u3066\u306e\u7d71\u8a08\u51e6\u7406\u53ca\u3073\u56de\u5e30\u51e6\u7406<\/p>\n<\/blockquote>\n<h2 id=\"i-1\">\u306a\u305cPandas\u3092\u5b66\u3076\u306e\u304b<\/h2>\n<p>\u306a\u305cPandas\u3092\u5b66\u3076\u306e\u304b\u306b\u3064\u3044\u3066\u8aac\u660e\u3057\u307e\u3059\u3002<br><strong>\u6a5f\u68b0\u5b66\u7fd2\u306b\u304a\u3044\u3066\u30c7\u30fc\u30bf\u306e\u524d\u51e6\u7406\u306f\u591a\u304f\u306e\u6642\u9593\u3092\u5272\u304f\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u304c\u3001Pandas\u3092\u4f7f\u3046\u3053\u3068\u3067\u3053\u306e\u30c7\u30fc\u30bf\u306e\u524d\u51e6\u7406\u3068\u3044\u3046\u5de5\u7a0b\u3092\u52b9\u7387\u3088\u304f\u884c\u3046\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/strong><br>\u6a5f\u68b0\u5b66\u7fd2\u30a8\u30f3\u30b8\u30cb\u30a2\u3084\u30c7\u30fc\u30bf\u30b5\u30a4\u30a8\u30f3\u30c6\u30a3\u30b9\u30c8\u304cPython\u3067\u30c7\u30fc\u30bf\u306e\u524d\u51e6\u7406\u3092\u3059\u308b\u4e0a\u3067\u5fc5\u8981\u306aPandas\u3092\u3053\u306e\u7ae0\u3067\u306f\u8aac\u660e\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h2 id=\"i-2\">Pandas\u3092\u4f7f\u3046\u30e1\u30ea\u30c3\u30c8<\/h2>\n<p>Pandas\u3092\u4f7f\u3046\u30e1\u30ea\u30c3\u30c8\u306f\u4e3b\u306b<strong><em>2\u3064<\/em><\/strong>\u3042\u308a\u307e\u3059\u3002<br><strong><em>1. \u591a\u7a2e\u306e\u578b\u306e\u30c7\u30fc\u30bf\u3092\u4e00\u3064\u306e\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u3067\u6271\u3048\u308b\u3053\u3068<\/em><\/strong><br>NumPy\u306e\u914d\u5217\uff08np.array\uff09\u306f\u3059\u3079\u3066\u306e\u8981\u7d20\u304c\u540c\u3058\u578b\u3067\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002<br>\u3088\u3063\u3066\u3001csv\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u66f8\u304d\u306a\u3069\u3067\u306f\u3001NumPy\u306f\u975e\u5e38\u306b\u4e0d\u4fbf\u306a\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002<br>\u305d\u306e\u70b9\u3001Pandas\u306e\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u306f\u7570\u306a\u308b\u578b\u306e\u30c7\u30fc\u30bf\u3092\u5165\u308c\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<br>Pandas\u306e\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u306b\u683c\u7d0d\u3059\u308b\u3053\u3068\u3067\u3001\u30c7\u30fc\u30bf\u306e\u524d\u51e6\u7406\u304c\u5bb9\u6613\u306b\u3067\u304d\u307e\u3059\u3002<br><strong><em>2.\u30c7\u30fc\u30bf\u52a0\u5de5\u3084\u89e3\u6790\u306e\u95a2\u6570\u304c\u591a\u3044\u3053\u3068<\/em><\/strong><br>\u5225\u7ae0\u3067\u793a\u3057\u305f\u6b20\u640d\u5024\u306e\u524a\u9664\u30fb\u88dc\u5b8c\u306e\u4ed6\u306b\u3082\u3001\u3053\u308c\u304b\u3089\u7d39\u4ecb\u3059\u308b\u69d8\u3005\u306a\u4fbf\u5229\u306a\u95a2\u6570\u304cPandas\u306b\u306f\u5099\u308f\u3063\u3066\u3044\u307e\u3059\u3002<br>\u305d\u3046\u3044\u3063\u305f\u69d8\u3005\u306a\u95a2\u6570\u306e\u4f7f\u3044\u65b9\u3092\u3053\u306e\u7ae0\u3067\u306f\u5b66\u3073\u307e\u3059\u3002<\/p>\n<h2 id=\"i-3\">Pandas\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/h2>\n<p>pip\u30b3\u30de\u30f3\u30c9\u3092\u7528\u3044\u305f<strong>Pandas<\/strong>\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u306f\u4e0b\u8a18\u306e\u30b3\u30de\u30f3\u30c9\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u51fa\u6765\u307e\u3059\u3002<br>Mac\u306e\u65b9\u306f\u30bf\u30fc\u30df\u30ca\u30eb\u3001Windows\u306e\u65b9\u306f\u30b3\u30de\u30f3\u30c9\u30d7\u30ed\u30f3\u30d7\u30c8\u4e0a\u3067\u5b9f\u884c\u3059\u308b\u3053\u3068\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n<pre><code class=\"shell\">pip install pandas\n<\/code><\/pre>\n<p>Jupyter Notebook\u3092\u304a\u4f7f\u3044\u306e\u65b9\u306f\u3001\u8d77\u52d5\u3057\u305fNotebook\u306e\u30bb\u30eb\u306b\u3001\u5148\u982d\u306b!\u30de\u30fc\u30af\u3092\u3064\u3051\u3066\u5b9f\u884c\u3059\u308b\u3053\u3068\u3067\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n<pre><code class=\"shell\">!pip install pandas\n<\/code><\/pre>\n<h2 id=\"i-4\">\n\n\n<\/h2>\n<h2 class=\"wp-block-heading\" id=\"i-5\">\n\n\n<\/h2>\n<h2 id=\"i-6\">Pandas\u3092\u4f7f\u3046<\/h2>\n<p>Pandas\u3092\u5229\u7528\u3059\u308b\u306b\u306f\u3001Pandas\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u8aad\u307f\u8fbc\u307f\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<br>\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3067\u3001Pandas\u3092pd\u3068\u3044\u3046\u540d\u524d\u3067\u6271\u3048\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre><code>import pandas as pd\n<\/code><\/pre>\n<h2 id=\"i-7\">\u30c7\u30fc\u30bf\u578b(pandas\u306e\u57fa\u672c\u30c7\u30fc\u30bf\u578b)<\/h2>\n<p><strong>Pandas\u306fNumPy\u3092\u30d9\u30fc\u30b9\u3068\u3057\u3066\u69cb\u7bc9\u3055\u308c\u3066\u3044\u308b\u305f\u3081\u3001NumPy\u306endarray\u3068\u306e\u76f8\u6027\u304c\u826f\u3044\u3067\u3059\u3002<\/strong><br>2\u3064\u306e\u30c7\u30fc\u30bf\u578b\u3067\u30c7\u30fc\u30bf\u3092\u4fdd\u6301\u3057\u307e\u3059\u3002<\/p>\n<p><strong>1.\u30b7\u30ea\u30fc\u30ba(Series)<\/strong><br><strong>2.\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0(DataFrame)<\/strong><br>1\u30641\u3064\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2 id=\"i-8\">\u30b7\u30ea\u30fc\u30ba<\/h2>\n<p>Series\u306f1\u5217\u306e\u307f\u306e\u30c7\u30fc\u30bf\u578b\u3067\u3059\u3002<\/p>\n<pre><code>import pandas as pd\n# from pandas import Series\n\ns1 = pd.Series([1,2,3,5])\nprint(s1)\n\n\"\"\"\n# \u5de6\u306e\u5217\u306f\u884c\u30e9\u30d9\u30eb\n\" \u53f3\u306e\u5217\u306f\u30b7\u30ea\u30fc\u30ba\u306e\u30c7\u30fc\u30bf\n0    1\n1    2\n2    3\n3    5\ndtype: int64 # \u30c7\u30fc\u30bf\u306e\u578b\n\"\"\"\n<\/code><\/pre>\n<p><strong>\u30b7\u30ea\u30fc\u30ba\u306f\u30c7\u30fc\u30bf(values)\u3068\u305d\u308c\u306b\u5bfe\u5fdc\u3059\u308b\u884c\u30e9\u30d9\u30eb(index)\u3092\u6301\u30641\u6b21\u5143\u30c7\u30fc\u30bf\u69cb\u9020\u3067\u3042\u308a\u3001\u8f9e\u66f8\u578b\u3068\u306f\u9055\u3063\u3066\u30c7\u30fc\u30bf\u306b\u306f\u9806\u756a\u304c\u3042\u308a\u307e\u3059\u3002<\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-9\">\u3010\u7121\u6599\u52d5\u753b\uff1a<strong>\u500d\u901f\u3067\u5b66\u3076\uff01\u751f\u6210AI\u3092\u6d3b\u7528\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u52c9\u5f37\u6cd5\uff08\u77ed\u7e2e\u7248\uff09\u3011<\/strong><\/h2>\n\n\n\n<p><\/p>\n\n\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-vimeo wp-block-embed-vimeo wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" src=\"https:\/\/player.vimeo.com\/video\/1069835048?h=e43b17d6de&amp;dnt=1&amp;app_id=122963\" width=\"880\" height=\"495\" frameborder=\"0\" allow=\"autoplay; fullscreen; picture-in-picture; clipboard-write; encrypted-media\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p><strong>\u5168\u7de8\u306f\u3001AI Academy\u516c\u5f0fLINE\u3067\u914d\u4fe1\u4e2d\u3067\u3059\u3002<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><a href=\"https:\/\/lin.ee\/3E4GzWk\" rel=\"nofollow noopener\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" width=\"910\" height=\"517\" src=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/LINE_Buttom.png\" alt=\"\" class=\"wp-image-6799\" style=\"width:158px;height:auto\" srcset=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/LINE_Buttom.png 910w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/LINE_Buttom-300x170.png 300w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/LINE_Buttom-768x436.png 768w\" sizes=\"auto, (max-width: 910px) 100vw, 910px\"><\/a><\/figure>\n\n\n<h2 id=\"i-10\">head()\u3068tail()<\/h2>\n<p>Pandas\u306e\u30c7\u30fc\u30bf\u306e\u4e2d\u8eab\u3092\u898b\u308b\u969b\u306b<strong>.head()<\/strong>\u3092\u4f7f\u3046\u3068\u5148\u982d\u304b\u30895\u4ef6\u3092\u8868\u793a\u3057\u3066\u304f\u308c\u307e\u3059\u3002<br>\u307e\u305f\u5f15\u6570\u306b\u6570\u5b57\u3092\u6e21\u3059\u3053\u3068\u3067\u305d\u306e\u4ef6\u6570\u5206\u5148\u982d\u304b\u3089\u53d6\u5f97\u53ef\u80fd\u3067\u3059\u3002<br>\u307e\u305f\u3001tail()\u3092\u4f7f\u3046\u3068\u672b\u5c3e\u304b\u30895\u4ef6\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<br>head()\u3068\u540c\u3058\u3088\u3046\u306b\u3001\u5f15\u6570\u306b\u6570\u5b57\u3092\u6e21\u3059\u3053\u3068\u3067\u305d\u306e\u4ef6\u6570\u5206\u672b\u5c3e\u304b\u3089\u53d6\u5f97\u53ef\u80fd\u3067\u3059\u3002<br>\u307e\u305f\u30c7\u30fc\u30bf\u306e\u5148\u982d\u3068\u672b\u5c3e\u304b\u3089\u540c\u6642\u306b\u30c7\u30fc\u30bf\u3092\u78ba\u8a8d\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<br>\u305d\u306e\u969b\u306b\u306f\u3001<strong>\u30c7\u30fc\u30bf.head().append(\u30c7\u30fc\u30bf.tail())<\/strong>\u3068\u8a18\u8ff0\u3059\u308b\u3053\u3068\u3067\u7e4b\u3052\u3066\u30c7\u30fc\u30bf\u3092\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre><code>import pandas as pd\nimport numpy as np\ndf = pd.DataFrame(np.random.randn(20,2))\ndf.head() # \u5148\u982d\u304b\u30895\u4ef6\ndf.tail()   # \u672b\u5c3e\u304b\u30895\u4ef6\ndf.head().append(df.tail()) # \u5148\u982d\u304b\u30895\u4ef6\u3068\u672b\u5c3e\u304b\u30895\u4ef6\u306e\u8a0810\u4ef6\u3092\u53d6\u5f97\ndf.head(3).append(df.tail(3)) # \u5148\u982d\u304b\u30893\u4ef6\u3068\u672b\u5c3e\u304b\u30893\u4ef6\u306e\u8a086\u4ef6\u3092\u53d6\u5f97\n<\/code><\/pre>\n<h2 id=\"i-11\">loc\u3068iloc<\/h2>\n<p>Pandas\u306e<strong>loc<\/strong>\u3068<strong>iloc<\/strong>\u306f\u5024\u3092\u62bd\u51fa\u3059\u308b\u305f\u3081\u306e\u30e1\u30bd\u30c3\u30c9\u3067\u3059\u3002<br>\u307e\u305a\u306f\u30b5\u30f3\u30d7\u30eb\u3068\u306a\u308b\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<pre><code>import pandas as pd\ndf = pd.DataFrame([[10, 20], [25, 50]], index=[\"1\u884c\", \"2\u884c\"], columns=[\"1\u5217\", \"2\u5217\"])\n<\/code><\/pre>\n<p>\u307e\u305a\u306f\u3001<strong>loc<\/strong>\u3092\u4f7f\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br>loc\u306f<strong>\u884c\u540d\u3082\u3057\u304f\u306f\u5217\u540d\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u7279\u5b9a\u306e\u5024\u3092\u62bd\u51fa\u3067\u304d\u307e\u3059\u3002<\/strong><br>1\u5217\u76ee\u30684\u5217\u76ee\u3092\u62bd\u51fa\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><code class=\"python:\">pirnt(df.loc[\"1\u884c\", :])\n<\/code><\/pre>\n<p>\u4e0a\u8a18\u3092\u5b9f\u884c\u3059\u308b\u3068\u6b21\u306e\u3088\u3046\u306b\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre><code class=\"shell:\">1\u5217    10\n2\u5217    20\nName: 1\u884c, dtype: int64\n<\/code><\/pre>\n<p>\u4ed6\u306b\u3082\u6b21\u306e\u3088\u3046\u306b\u66f8\u304f\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre><code class=\"python:\">print(df.loc[: , [\"1\u5217\", \"2\u5217\"]])\n<\/code><\/pre>\n<p>\u4e0a\u8a18\u3092\u5b9f\u884c\u3059\u308b\u3068\u6b21\u306e\u3088\u3046\u306b\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre><code class=\"shell:\">    1\u5217  2\u5217\n1\u884c  10  20\n2\u884c  25  50\n<\/code><\/pre>\n<p>\u5b58\u5728\u3057\u306a\u3044\u5217\u306b\u30a2\u30af\u30bb\u30b9\u3059\u308b\u3068NaN\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre><code class=\"python:\">print(df.loc[: , [\"1\u5217\", \"5\u5217\"]])\n<\/code><\/pre>\n<p>\u4e0a\u8a18\u3092\u5b9f\u884c\u3059\u308b\u3068\u6b21\u306e\u3088\u3046\u306b\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre><code class=\"shell\">    1\u5217  5\u5217\n1\u884c  10 NaN\n2\u884c  25 NaN\n<\/code><\/pre>\n<p>\u6b21\u306biloc\u3092\u898b\u3066\u3044\u304d\u307e\u3057\u3087\u3046\u3002<br><strong>iloc\u306findex\u3092\u6307\u5b9a\u3059\u308b\u3053\u3068\u3067\u7279\u5b9a\u306e\u5024\u3092\u62bd\u51fa\u3067\u304d\u307e\u3059\u3002<\/strong><\/p>\n<pre><code class=\"python:\"># df.iloc[\u884c, \u5217]\nprint(df.iloc[1:2])# index\u6307\u5b9a\u304c\u53ef\u80fd\n<\/code><\/pre>\n<p>\u4e0a\u8a18\u3092\u5b9f\u884c\u3059\u308b\u3068\u6b21\u306e\u3088\u3046\u306b\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre><code class=\"shell\">    1\u5217  2\u5217\n2\u884c  25  50\n<\/code><\/pre>\n<p>\u307e\u305f\u3001<code class=\"inline-code inline\" data-v-62aad88c=\"\" data-v-9477a4ba=\"\" data-v-655fa08f=\"\">loc<\/code><span class=\"inline-raw inline\" data-v-7a7589cf=\"\" data-v-9477a4ba=\"\" data-v-655fa08f=\"\">\u3068<\/span>iloc\u306f\u30b9\u30e9\u30a4\u30b9\u8868\u8a18\u3092\u7528\u3044\u308b\u3053\u3068\u304c\u51fa\u6765\u308b\u305f\u3081\u6b21\u306e\u3088\u3046\u306b\u8a18\u8ff0\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<p>iloc\u3092\u4f7f\u3063\u3066\u30b9\u30e9\u30a4\u30b9\u8868\u8a18\u3092\u66f8\u3044\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u4ee5\u4e0b\u306e\u901a\u308a\u3067\u3059\u3002<\/p>\n<pre><code class=\"python:\">print(df.iloc[:, -1])  # \u8ca0\u306e\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\u3092\u4f7f\u3044\u3001\u672b\u5c3e\u306e\u8981\u7d20\u304b\u3089\u4f4d\u7f6e\u6307\u5b9a\u30572\u5217\u76ee\u306e\u5168\u3066\u306e\u884c\u3092\u53d6\u5f97\u3002\n<\/code><\/pre>\n<pre><code class=\"shell:\">1\u884c    20\n2\u884c    50\nName: 2\u5217, dtype: int64\n<\/code><\/pre>\n<h2 id=\"i-12\">\u6761\u4ef6\u306b\u3088\u308b\u884c\u306e\u62bd\u51fa(query)<\/h2>\n<p><strong>query<\/strong>\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u3067pandas.DataFrame\u306e\u5217\u306e\u5024\u306b\u5bfe\u3057\u3001\u6761\u4ef6\u306b\u5fdc\u3058\u3066\u884c\u3092\u62bd\u51fa\u3059\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<br>\u6bd4\u8f03\u6f14\u7b97\u5b50\u3092\u5229\u7528\u3057\u305f\u8907\u6570\u306e\u6761\u4ef6\u6307\u5b9a\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n<pre><code class=\"python:\">import pandas as pd\ndf = pd.DataFrame([[10, 20,30, 30], [25, 50,65, 80]], index=[\"1\u884c\", \"2\u884c\"], columns=[\"A\", \"B\", \"C\", \"D\"])\nprint(df)\n<\/code><\/pre>\n<p>\u4e0a\u8a18\u3092\u5b9f\u884c\u3059\u308b\u3068\u6b21\u306e\u3088\u3046\u306b\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre><code class=\"shell\">     A   B   C   D\n1\u884c  10  20  30  30\n2\u884c  25  50  65  80\n<\/code><\/pre>\n<p>\u6b21\u306b\u6b21\u306e\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u5b9f\u884c\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><code class=\"python:\">print(df.query('A &gt;= 5 and C &lt; 50'))\n<\/code><\/pre>\n<p>\u4e0a\u8a18\u3092\u5b9f\u884c\u3059\u308b\u3068\u6b21\u306e\u3088\u3046\u306b\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre><code class=\"shell\">     A   B   C   D\n1\u884c  10  20  30  30\n<\/code><\/pre>\n<h2 id=\"i-13\">\u30c7\u30fc\u30bf\u306e\u5165\u51fa\u529b<\/h2>\n<p>Pnadas\u306b\u306f\u3001<span class=\"inline-raw inline\" data-v-7a7589cf=\"\" data-v-9477a4ba=\"\" data-v-655fa08f=\"\">\u30d5\u30a1\u30a4\u30eb\u3092\u5165\u51fa\u529b\u3059\u308b\u6a5f\u80fd\u3068\u3057\u3066\u3001\u5927\u304d\u304f4\u3064\u306e\u6a5f\u80fd\u3092\u63d0\u4f9b\u3057\u3066\u3044\u307e\u3059\u3002<\/span><\/p>\n<p><strong>1. \u30c6\u30ad\u30b9\u30c8\u5f62\u5f0f\u306e\u30c7\u30fc\u30bf\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f<\/strong><br><strong>2. \u30d0\u30a4\u30ca\u30ea\u5f62\u5f0f\u306e\u30c7\u30fc\u30bf\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f<\/strong><br><strong>3. \u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\u306e\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f<\/strong><br><strong>4. Web\u4e0a\u304b\u3089\u306e\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f<\/strong><\/p>\n<p>\u4f8b\u3048\u3070\u3001Pandas\u3067csv\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080\u5834\u5408\u306f\u3001\u300cread_csv\u300d\u3092\u4f7f\u3044\u3001\u30c7\u30fc\u30bf\u306e\u51fa\u529b\u306b\u306f\u300cto_csv\u300d\u3084\u300cto_excel\u300d\u306a\u3069\u304c\u5229\u7528\u53ef\u80fd\u3067\u3059\u3002csv\u4ee5\u5916\u306b\u3082\u3001\u300cread_json\u300d\u3084\u300cread_excel\u300d\u3001\u300cread_json\u300d\u300cread_sql\u300d\u3082\u3042\u308a\u3001\u305d\u308c\u3089\u306e\u51fa\u529b\u30e1\u30bd\u30c3\u30c9\u3082\u3042\u308a\u307e\u3059\u3002<br>TSV\u30d5\u30a1\u30a4\u30eb\u306e\u5834\u5408\u306f\u3001\u300cread_table\u300d\u3092\u4f7f\u3046\u3053\u3068\u3067\u533a\u5207\u308a\u6587\u5b57\u304c\u30bf\u30d6\\t\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u51e6\u7406\u3059\u308b\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<br>\u8a66\u3057\u306bcsv\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3093\u3067\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre><code class=\"python:\">import pandas as pd\ndata = pd.read_csv(\"https:\/\/aiacademy.jp\/dataset\/sample_data.csv\",\n                   encoding=\"cp932\",\n                   skiprows=1, # 1\u884c\u8aad\u307f\u98db\u3070\u3059\n                   )\nprint(data)\nprint(type(data)) # &lt;class 'pandas.core.frame.DataFrame'&gt;\nprint(data.dtypes)\n\"\"\"\n\u30a8\u30af\u30bb\u30eb\u306e\u5834\u5408\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u4f7f\u3044\u307e\u3059\u3002\n.read_excel(\"\u4efb\u610f\u306e\u30d5\u30a1\u30a4\u30eb\u540d.xlsx\",encoding='utf8')\n\"\"\"\n<\/code><\/pre>\n<h2 id=\"i-14\">Pandas \u30bd\u30fc\u30c8<\/h2>\n<p><em>\u30a4\u30f3\u30c7\u30c3\u30af\u30b9 (\u884c\u540d\u30fb\u5217\u540d)\u3092\u4f7f\u3046\u65b9\u6cd5\u3068\u5024\u306b\u57fa\u3065\u3044\u3066\u30bd\u30fc\u30c8\u3059\u308b\u65b9\u6cd5\u304c\u3042\u308a\u307e\u3059\u3002<\/em><br><strong>.sort_index()<\/strong>\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\uff08\u30ab\u30e9\u30e0\u540d\u3001\u884c\u540d\uff09\u306b\u57fa\u3065\u3044\u3066\u30bd\u30fc\u30c8\u3092\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<br>\u305d\u306e\u307e\u307e\u4f7f\u3046\u3068\u3001\u6607\u9806\uff08\u5c0f\u3055\u3044\u9806\uff09\u3067\u306e\u30bd\u30fc\u30c8\u3068\u306a\u308a\u307e\u3059\u304c\u3001\u5f15\u6570\u306b\u3001<strong>ascending=False<\/strong>\u3092\u8a18\u8ff0\u3059\u308b\u3053\u3068\u3067\u964d\u9806(\u5927\u304d\u3044\u9806)\u306e\u30bd\u30fc\u30c8\u304c\u3067\u304d\u307e\u3059\u3002<br><strong>.sort_values(by=\u30ab\u30e9\u30e0\u306e\u30ea\u30b9\u30c8)<\/strong>\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001\u5217\u306e\u5024\u306e\u5c0f\u3055\u3044\u9806\u306b\u30bd\u30fc\u30c8\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre><code class=\"python:\">import pandas as pd\nimport numpy as np\ndf = pd.DataFrame(np.random.randn(20,2))\ndf.sort_index(ascending=False) # \u964d\u9806\n# \u6607\u9806\u3067\u30bd\u30fc\u30c8\u3059\u308b\u306b\u306f\u4e0a\u8a18\u306e\u964d\u9806\u30bd\u30fc\u30c8\u306e\u30b3\u30fc\u30c9\u3092\u30b3\u30e1\u30f3\u30c8\u30a2\u30a6\u30c8\u3057\u3066\u4e0b\u8a18\u3092\u5b9f\u884c\u3057\u3066\u304f\u3060\u3055\u3044\ndf.sort_values(by=1) # key(\u30ab\u30e9\u30e0\u540d)\u304c1\u306e\u6607\u9806(\u5c0f\u3055\u3044\u9806)\u3067\u30bd\u30fc\u30c8\ndf.sort_values(by=1, ascending=False)  # key\u304c1\u306e\u964d\u9806(\u5927\u304d\u3044\u9806)\u3067\u30bd\u30fc\u30c8\n<\/code><\/pre>\n<p>\u4e0a\u8a18\u3092\u5b9f\u884c\u3059\u308b\u3068\u6b21\u306e\u3088\u3046\u306b\u51fa\u529b\u3055\u308c\u307e\u3059\u3002<br>\uff08random.randn()\u3092\u7528\u3044\u3066\u3044\u308b\u305f\u3081\u3001\u5b9f\u884c\u3054\u3068\u306b\u3088\u3063\u3066\u51fa\u529b\u304c\u5909\u308f\u308a\u307e\u3059\u3002\uff09<\/p>\n<pre><code class=\"shell\">           0         1\n8  -0.873384  2.444225\n12 -1.452744  1.261722\n6  -0.024629  1.148419\n5  -0.343477  1.130691\n18  0.693656  1.098463\n13  1.210782  1.064755\n14  0.367597  0.777216\n0   0.359690  0.699058\n1   0.084761  0.479651\n4  -0.227558  0.094337\n17  0.829182  0.053559\n11  0.060647  0.047543\n15 -0.247204 -0.413310\n16 -0.209684 -0.638343\n3  -0.238448 -0.667186\n2   1.343385 -0.706601\n7  -0.255831 -1.206057\n19  0.613618 -1.282351\n10 -0.294631 -1.353662\n9   0.572267 -1.963924\n<\/code><\/pre>\n<h2 id=\"i-15\">\u6b20\u640d\u5024\u306e\u51e6\u7406<\/h2>\n<p>Pandas\u306b\u306f\u6b20\u640d\u5024(NaN)\u306e\u6271\u3046\u30e1\u30bd\u30c3\u30c9\u306f<strong>\u300cdropna\u300d<\/strong>\u3001<strong>\u300cfillna\u300d<\/strong>\u3001<strong>\u300cisnull\u300d<\/strong>\u3001<strong>\u300cnotnull\u300d<\/strong>\u304c\u3042\u308a\u307e\u3059\u3002<br>1\u30641\u3064\u89e3\u8aac\u3057\u3066\u3044\u304d\u307e\u3059\u3002<br>\u307e\u305a<strong>dropna\u306f\u6307\u5b9a\u306e\u8ef8\u65b9\u5411\u306b\u30c7\u30fc\u30bf\u5217\u3092\u898b\u3066\u3001\u6b20\u640d\u5024(NaN)\u306e\u6709\u7121\u306b\u95a2\u3057\u3066\u6307\u5b9a\u306e\u6761\u4ef6\u3092\u6e80\u305f\u3059\u5834\u5408\u306b\u3001\u305d\u306e\u30c7\u30fc\u30bf\u5217\u3092\u524a\u9664\u3057\u307e\u3059\u3002<\/strong><br><strong>fillna\u306f\u6b20\u640d\u5024\u3092\u6307\u5b9a\u306e\u5024\u3082\u3057\u304f\u306f\u3001\u6307\u5b9a\u306e\u65b9\u6cd5\u3067\u57cb\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/strong><br><strong>isnull\u306f\u30c7\u30fc\u30bf\u306e\u8981\u7d20\u3054\u3068\u306bNaN\u306fTrue\u3001\u305d\u308c\u4ee5\u5916\u3092False\u3068\u3057\u3066\u6271\u3044\u3001\u5143\u306e\u30c7\u30fc\u30bf\u3068\u540c\u3058\u30b5\u30a4\u30ba\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3057\u307e\u3059\u3002<br>notnull\u306fisnull\u3068\u306f\u9006\u306e\u771f\u507d\u5024\u3092\u8fd4\u3057\u307e\u3059\u3002<\/strong><\/p>\n<pre><code class=\"python:\">import numpy as np\nimport pandas as pd\ndf = pd.DataFrame({\"int\": [1, np.nan, np.nan, 32],\n                   \"str\": [\"python\", \"ai\", np.nan, np.nan],\n                   \"flt\": [5.5, 4.2, -1.2, np.nan]})\nprint(df)\n# df\u6210\u5206\u306b\u5bfe\u3057\u3066NaN\u306e\u5730\u4f4d\u3092True\u3068\u3057\u305f\u30d6\u30fc\u30eb\u306e\u5024\u306e\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u3092\u8fd4\u3059\nprint(df.isnull()) # notnull()\u3092\u4f7f\u3046\u3068\u3001True\u3068False\u304c\u9006\u306e\u51e6\u7406\u306b\u306a\u308b\u3002\n# \"int\"\u5217\u306bNaN\u304c\u3042\u308b\u884c\u306e\u524a\u9664\nprint(df.dropna(subset=[\"int\"]))\n# NaN\u304c\u3042\u308b\u884c\u3092\u5168\u3066\u524a\u9664\u3059\u308b\nprint(df.dropna())\n# NaN\u3092\u5168\u30660\u306b\u7f6e\u63db\u3059\u308b\nprint(df.fillna(0)) # \u7b2c\u4e00\u5f15\u6570\u306bmethod=\"ffill\" \u7b2c\u4e8c\u5f15\u6570\u306blimtit=\u6570\u5b57 \u3068\u3059\u308b\u3053\u3068\u3067\u6307\u5b9a\u3057\u305f\u6570\u5b57\u307e\u3067\u306f\u524d\u306e\u30c7\u30fc\u30bf\u3092\u4f7f\u3063\u3066NaN\u3092\u57cb\u3081\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\ndf2 = pd.DataFrame({\"int\": [1, np.nan, np.nan, 32],\n                   \"str\": [\"python\", \"ai\", np.nan, np.nan],\n                   \"flt\": [5.5, 4.2, -1.2, np.nan]})\n# int\u5217\u3060\u30510\u3067\u88dc\u5b8c\ndf2.fillna({\"int\": 0}) # \u7279\u5b9a\u306e\u5217\u306b\u5bfe\u3057\u3066\u306f\u8f9e\u66f8\u578b\u3092\u7528\u3044\u308b\n# \u5217\u3054\u3068\u306b\u7570\u306a\u308b\u5024\u3092\u4f7f\u3044\u305f\u3044\u6642\u306f\u8907\u6570\u306e\u30ad\u30fc\u3092\u6e21\u3059\u3002\ndf2.fillna({\"int\": 0, \"str\": \"ai\"}) \n# \u7279\u5b9a\u306e\u5217(\u4f8b\u3048\u3070flt)\u3092\u524a\u9664\ndf2.drop(labels=\"flt\",axis=1)\n\"\"\"\n  int str\n0 1.0 python\n1 NaN ai\n2 NaN NaN\n3 32.0  NaN\n\"\"\"\n# \u8907\u6570\u306e\u5217\u3092\u524a\u9664\ndf2.drop(labels=[\"flt\", \"str\"],axis=1)\n\"\"\"\n  int\n0 1.0\n1 NaN\n2 NaN\n3 32.0\n\"\"\"\n# index\u3092\u6307\u5b9a\u3059\u308b\u3068\u884c\u3092\u6d88\u3059\u3053\u3068\u3082\u3067\u304d\u307e\u3059\ndf2.drop(index=1, axis=0)\n\"\"\"\nint str flt\n0 1.0 python  5.5\n2 NaN NaN -1.2\n3 32.0  NaN NaN\n\"\"\"\n# \u5143\u306e\u30c7\u30fc\u30bf\u306b\u53cd\u6620\u3057\u3066\u524a\u9664\u3059\u308b\u306b\u306finplace\u30aa\u30d7\u30b7\u30e7\u30f3\u306bTrue\u3092\u6e21\u3057\u307e\u3059\ndf2.drop(labels=\"flt\", axis=1, inplace=True)\nprint(df2)\n\"\"\"\nint str\n0 1.0 python\n1 NaN ai\n2 NaN NaN\n3 32.0  NaN\n\"\"\"\n<\/code><\/pre>\n<p>\u30e9\u30f3\u30c0\u30e0\u306b6\u884c\uff13\u5217\u306e\u30c7\u30fc\u30bf\u3092\u751f\u6210\u3059\u308b\u306b\u306f\u6b21\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre><code>import numpy as np\nimport pandas as pd\ndf3 = pd.DataFrame(np.random.rand(6,3))\nprint(df3) # \u30c7\u30fc\u30bf\u306e\u78ba\u8a8d\n<\/code><\/pre>\n<h2 id=\"i-16\">\u307e\u3068\u3081<\/h2>\n<p>\u3053\u306e\u7ae0\u3067\u306f\u3001Pandas\u306e2\u3064\u306e\u30c7\u30fc\u30bf\u578b(Series\u3068DataFrame)\u3084\u30c7\u30fc\u30bf\u306e\u62bd\u51fa\u65b9\u6cd5\u3084\u8aad\u307f\u8fbc\u307f\u65b9\u6cd5\u306a\u3069\u306b\u95a2\u3059\u308b\u51e6\u7406\u3092\u5b66\u3093\u3067\u304d\u307e\u3057\u305f\u3002<br>Pandas\u306b\u306f\u3053\u3053\u3067\u306f\u7d39\u4ecb\u3057\u3066\u3044\u306a\u3044\u30c7\u30fc\u30bf\u89e3\u6790\u3092\u5bb9\u6613\u306b\u3059\u308b\u6a5f\u80fd\u3092\u63d0\u4f9b\u3057\u3066\u3044\u307e\u3059\u306e\u3067\u3001\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306a\u3069\u3092\u53c2\u8003\u306b\u3057\u3066\u3055\u3089\u306b\u4f7f\u3044\u3053\u306a\u305b\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u3087\u3046\u3002<\/p>\n<h2 id=\"i-17\">\u6f14\u7fd2\u554f\u984c<\/h2>\n<p>\u203b\u3053\u306e\u7ae0\u306e\u6f14\u7fd2\u554f\u984c\u3067\u306f\u3001excel\u306e\u8aad\u307f\u8fbc\u307f\u3092\u884c\u3044\u307e\u3059\u3002<br>\u305d\u306e\u969b\u306b\u3001ModuleNotFoundError: No module named \u2018openpyxl\u2019\u30a8\u30e9\u30fc\u304c\u51fa\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<br>\u30a8\u30e9\u30fc\u304c\u51fa\u305f\u5834\u5408\u306f\u3001pip\u306a\u3069\u3092\u7528\u3044\u3066openpyxl\u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre><code class=\"shell\">pip install openpyxl\n<\/code><\/pre>\n<ol>\n<li>\u30b7\u30ea\u30fc\u30ba\u306e\u30c7\u30fc\u30bf\u578b\u3092\u81ea\u7531\u306b\u4f5c\u3063\u3066\u304f\u3060\u3055\u3044\u3002<\/li>\n<li>\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u306e\u30c7\u30fc\u30bf\u578b\u3092\u81ea\u7531\u306b\u4f5c\u3063\u3066\u304f\u3060\u3055\u3044\u3002<\/li>\n<li>\u3042\u308bSNS\u30b5\u30fc\u30d3\u30b9\u306e\u30e6\u30fc\u30b6\u30fc10\u4eba\u306e\u30d5\u30a9\u30ed\u30fc\u6570\u3084\u30d5\u30a9\u30ed\u30ef\u30fc\u6570\u306ecsv\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u308a\u307e\u3059\u3002<br>\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u306e\u30d8\u30c3\u30c0\u30fc\u304c\u30e6\u30fc\u30b6\u30fcID,\u30d5\u30a9\u30ed\u30fc,\u30d5\u30a9\u30ed\u30ef\u30fc,\u3044\u3044\u306d\u304c\u4e0e\u3048\u3089\u308c\u3066\u304a\u308a\u307e\u3059\u3002<br>\u3053\u308c\u3089\u305d\u308c\u305e\u308cuser_id,follow,follower,like\u306b\u5909\u63db\u3057\u305foutput.csv\u30d5\u30a1\u30a4\u30eb\u3092\u51fa\u529b\u3057\u3066\u304f\u3060\u3055\u3044\u3002<br>\u30c7\u30fc\u30bf\u306f\u4e0b\u8a18URL\u306b\u3042\u308a\u307e\u3059\u306e\u3067\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/li>\n<li><strong>d1 = {\u201cdata1\u201d: [\u201ca\u201d,\u201db\u201d,\u201dc\u201d,\u201dd\u201d,\u201dc\u201d,\u201da\u201d], \u201cdata2\u201d: range(6)}<\/strong>\u3092\u4f7f\u3063\u3066\u3001d1\u3068\u3044\u3046\u540d\u524d\u306eDataFrame\u3092\u4f5c\u3063\u3066\u304f\u3060\u3055\u3044\u3002<\/li>\n<li>4\u3067\u4f5c\u3063\u305f\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u3092csv\u30d5\u30a1\u30a4\u30eb(.csv)\u3068\u30a8\u30af\u30bb\u30eb\u30d5\u30a1\u30a4\u30eb(.xlsx)\u306b\u66f8\u304d\u51fa\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/li>\n<li>5\u3067\u4f5c\u6210\u3055\u308c\u305f\u30a8\u30af\u30bb\u30eb\u30d5\u30a1\u30a4\u30eb(.xlsx)\u3068csv\u30d5\u30a1\u30a4\u30eb(.csv)\u3092\u305d\u308c\u305e\u308c\u8aad\u307f\u8fbc\u3093\u3067\u304f\u3060\u3055\u3044\u3002<\/li>\n<li>5\u3067\u4f5c\u6210\u3057\u305f\u30a8\u30af\u30bb\u30eb\u30d5\u30a1\u30a4\u30eb\u306b\u65b0\u3057\u3044\u5217(\u30ab\u30e9\u30e0)\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/li>\n<li>7\u306b\u5bfe\u3057\u3066append\u3092\u4f7f\u3044\u3001\u884c\u3092\u8ffd\u52a0\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/li>\n<\/ol>\n<p><a href=\"https:\/\/qiita.com\/AI_Academy\/private\/fca5820546cd20083835\" target=\"_blank\" rel=\"noopener nofollow\">\u6f14\u7fd2\u554f\u984c\u56de\u7b54\u4f8b<\/a><br><a href=\"https:\/\/aiacademy.jp\/dataset\/sns_data.csv\" target=\"_blank\" rel=\"noopener\">SNS\u30d5\u30a9\u30ed\u30fc\u30c7\u30fc\u30bf<\/a><br><a href=\"https:\/\/aiacademy.jp\/dataset\/21.py\" target=\"_blank\" rel=\"noopener\">\u56de\u7b54\u4f8b\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/a><\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"i-18\">Pandas\u3092\u306f\u3058\u3081\u3066\u5b66\u3076\u3042\u306a\u305f\u3078\uff1a\u3088\u304f\u3042\u308b\u8cea\u554f\u3068\u56de\u7b54<\/h2>\n\n\n\n<p><strong><span class=\"keiko_blue\">Q1. Pandas\u3068NumPy\u306e\u9055\u3044\u306f\u4f55\u3067\u3059\u304b\uff1f<\/span><\/strong><br>A. NumPy\u306f\u4e3b\u306b\u6570\u5024\u8a08\u7b97\u5411\u3051\u306e\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3001\u914d\u5217\uff08ndarray\uff09\u3092\u6271\u3044\u307e\u3059\u3002\u4e00\u65b9\u3001Pandas\u306f\u8868\u5f62\u5f0f\u306e\u30c7\u30fc\u30bf\uff08DataFrame\u3084Series\uff09\u3092\u6271\u3046\u306e\u306b\u9069\u3057\u3066\u304a\u308a\u3001\u7570\u306a\u308b\u30c7\u30fc\u30bf\u578b\u3092\u67d4\u8edf\u306b\u7ba1\u7406\u3067\u304d\u307e\u3059\u3002\u30c7\u30fc\u30bf\u5206\u6790\u3084\u524d\u51e6\u7406\u306b\u306fPandas\u304c\u3088\u304f\u4f7f\u308f\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<p><strong><span class=\"keiko_blue\">Q2. Pandas\u306f\u6a5f\u68b0\u5b66\u7fd2\u306b\u3069\u3046\u5f79\u7acb\u3061\u307e\u3059\u304b\uff1f<\/span><\/strong><br>A. \u6a5f\u68b0\u5b66\u7fd2\u3067\u6700\u3082\u6642\u9593\u304c\u304b\u304b\u308b\u300c\u30c7\u30fc\u30bf\u306e\u524d\u51e6\u7406\u300d\u3092\u52b9\u7387\u5316\u3067\u304d\u307e\u3059\u3002\u6b20\u640d\u5024\u51e6\u7406\u3001\u7279\u5fb4\u91cf\u30a8\u30f3\u30b8\u30cb\u30a2\u30ea\u30f3\u30b0\u3001\u30c7\u30fc\u30bf\u5909\u63db\u3001\u96c6\u8a08\u306a\u3069\u3092Pandas\u3067\u884c\u3046\u3053\u3068\u3067\u3001\u30e2\u30c7\u30eb\u69cb\u7bc9\u307e\u3067\u306e\u6e96\u5099\u304c\u30b9\u30e0\u30fc\u30ba\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n\n\n\n<p><strong><span class=\"keiko_blue\">Q<\/span><span class=\"keiko_blue\">3<\/span><span class=\"keiko_blue\">. Pandas\u306e\u30d0\u30fc\u30b8\u30e7\u30f3\u306f\u3069\u3053\u3067\u78ba\u8a8d\u3067\u304d\u307e\u3059\u304b\uff1f<\/span><\/strong><br>A. \u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3067\u78ba\u8a8d\u3067\u304d\u307e\u3059\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import pandas as pd  \nprint(pd.__version__)<\/code><\/pre>\n\n\n\n<p>\u30d0\u30fc\u30b8\u30e7\u30f3\u306b\u3088\u3063\u3066\u4e00\u90e8\u6a5f\u80fd\u3084\u5f15\u6570\u304c\u7570\u306a\u308b\u5834\u5408\u304c\u3042\u308b\u305f\u3081\u3001\u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u3067\u5bfe\u5fdc\u30d0\u30fc\u30b8\u30e7\u30f3\u3092\u78ba\u8a8d\u3059\u308b\u3053\u3068\u3092\u304a\u3059\u3059\u3081\u3057\u307e\u3059\u3002<\/p>\n\n\n\n<p><strong><span class=\"keiko_blue\">Q4. Pandas\u3092\u5b66\u3076\u4e0a\u3067\u304a\u3059\u3059\u3081\u306e\u53c2\u8003\u8cc7\u6599\u306f\uff1f<\/span><\/strong><br>A. \u516c\u5f0f\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u304c\u6700\u3082\u4fe1\u983c\u6027\u304c\u9ad8\u304f\u7db2\u7f85\u7684\u3067\u3059\u3002\u307e\u305f\u30aa\u30f3\u30e9\u30a4\u30f3\u8b1b\u5ea7\uff08AI Academy Bootcamp\uff01\uff09\u3092\u4f75\u7528\u3059\u308b\u3068\u7406\u89e3\u304c\u6df1\u307e\u308a\u307e\u3059\u3002\u5b9f\u969b\u306b\u30b3\u30fc\u30c9\u3092\u66f8\u304d\u306a\u304c\u3089\u8a66\u3059\u306e\u304c\u4e0a\u9054\u306e\u30b3\u30c4\u3067\u3059\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"i-19\">\u2728AI\u4eba\u6750\u30b3\u30fc\u30b9 \u53d7\u8b1b\u304a\u7533\u8fbc\u307f\u53d7\u4ed8\u4e2d\uff01&nbsp;<\/h2>\n\n\n\n<p><a href=\"https:\/\/aiacademy.jp\/bootcamp\" target=\"_blank\" rel=\"noreferrer noopener\">AI Academy Bootcamp<\/a>&nbsp;\u3067\u306fAI\u30fb\u30c7\u30fc\u30bf\u30b5\u30a4\u30a8\u30f3\u30b9\u3001\u6a5f\u68b0\u5b66\u7fd2\u3001Web\u30a2\u30d7\u30ea\u958b\u767a\u306e\u5b9f\u8df5\u529b\u3092\u9ad8\u3081\u308b\u5168\uff16\u30b3\u30fc\u30b9\u7d0450\u6642\u9593\u4ee5\u4e0a\u306e\u52d5\u753b\u304c\u898b\u653e\u984c\uff01AI\u306e\u5b66\u7fd2\u306b\u5fc5\u9808\u306ePython\u306e\u5b66\u7fd2\u304b\u3089\u59cb\u307e\u308a\u3001IT\u30ea\u30c6\u30e9\u30b7\u30fc\u3001LLM\u5b66\u7fd2\u306a\u3069\u3001\u76ee\u7684\u306b\u5fdc\u3058\u305f\u5e45\u5e83\u3044\u5206\u91ce\u3092\u30ab\u30d0\u30fc\u3057\u3066\u3044\u307e\u3059\u3002<span class=\"keiko_blue\">LINE\u516c\u5f0f\u3067\u306f\u3001\u304a\u5f97\u306a\u5272\u5f15\u30af\u30fc\u30dd\u30f3\u3082\u30d7\u30ec\u30bc\u30f3\u30c8<\/span>\u3057\u3066\u3044\u307e\u3059\uff01<\/p>\n\n\n\n<p><strong>\u5358\u72ec\u3067\u5b66\u3076\u3088\u308a\u3001\u5168\u30b3\u30fc\u30b9\u3092\u4e00\u6c17\u306b\u5b66\u3076\u3053\u3068\u3067\u5f97\u3089\u308c\u308b\u300c\u5b66\u7fd2\u30b7\u30ca\u30b8\u30fc\u52b9\u679c\u300d\u304c\u7279\u9577\u3002<\/strong><br>\u57fa\u790e\u304b\u3089\u5fdc\u7528\u307e\u3067\u3001\u30c7\u30fc\u30bf\u5206\u6790\u3068AI\u958b\u767a\u306e\u30b9\u30ad\u30eb\u3092\u52b9\u7387\u3088\u304f\u8eab\u306b\u3064\u3051\u3089\u308c\u307e\u3059\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><a href=\"https:\/\/lin.ee\/3E4GzWk\" target=\"_blank\" rel=\" noreferrer noopener nofollow\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"349\" src=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/\u30af\u30fc\u30dd\u30f3Media06-1024x349.png\" alt=\"\" class=\"wp-image-7228\" style=\"width:900px;height:auto\" srcset=\"https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/\u30af\u30fc\u30dd\u30f3Media06-1024x349.png 1024w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/\u30af\u30fc\u30dd\u30f3Media06-300x102.png 300w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/\u30af\u30fc\u30dd\u30f3Media06-768x261.png 768w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/\u30af\u30fc\u30dd\u30f3Media06-1536x523.png 1536w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/\u30af\u30fc\u30dd\u30f3Media06-2048x697.png 2048w, https:\/\/aiacademy.jp\/media\/wp-content\/uploads\/2019\/11\/\u30af\u30fc\u30dd\u30f3Media06-940x320.png 940w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\"><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u76ee\u6b21 Pandas\u3068\u306f \u306a\u305cPandas\u3092\u5b66\u3076\u306e\u304b Pandas\u3092\u4f7f\u3046\u30e1\u30ea\u30c3\u30c8 Pandas\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb Pandas\u3092\u4f7f\u3046 \u30c7\u30fc\u30bf\u578b(pandas\u306e\u57fa\u672c\u30c7\u30fc\u30bf\u578b) \u30b7\u30ea\u30fc\u30ba \u3010\u7121\u6599\u52d5\u753b\uff1a\u500d\u901f\u3067\u5b66\u3076\uff01\u751f\u6210AI\u3092\u6d3b\u7528\u3057\u305f &#8230; <\/p>\n","protected":false},"author":1,"featured_media":7211,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[85,173,105],"tags":[],"class_list":{"0":"post-152","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python","8":"category-pandas","9":"category-105"},"_links":{"self":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=152"}],"version-history":[{"count":74,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/152\/revisions"}],"predecessor-version":[{"id":7472,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/posts\/152\/revisions\/7472"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=\/wp\/v2\/media\/7211"}],"wp:attachment":[{"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aiacademy.jp\/media\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}