{"id":2411,"date":"2025-08-21T20:32:12","date_gmt":"2025-08-21T11:02:12","guid":{"rendered":"https:\/\/softasia.jp\/blog\/?p=2411"},"modified":"2025-10-29T19:49:56","modified_gmt":"2025-10-29T10:19:56","slug":"python%e5%85%a5%e9%96%80%ef%bc%81csv%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e6%93%8d%e4%bd%9c%e6%96%b9%e6%b3%95%e3%82%92%e5%be%b9%e5%ba%95%e8%a7%a3%e8%aa%ac%ef%bc%81-pandas%e3%81%ae%e4%bd%bf%e3%81%84","status":"publish","type":"post","link":"https:\/\/softasia.jp\/blog\/offshore\/2411\/","title":{"rendered":"Python\u5165\u9580\uff01CSV\u30d5\u30a1\u30a4\u30eb\u64cd\u4f5c\u65b9\u6cd5\u3092\u5fb9\u5e95\u89e3\u8aac\uff01 Pandas\u306e\u4f7f\u3044\u65b9\u3082\u5408\u308f\u305b\u3066\u7d39\u4ecb"},"content":{"rendered":"<p><img loading=\"lazy\" class=\"size-medium wp-image-2458 aligncenter\" src=\"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/SOFT_ASIA_\u30a2\u30a4\u30ad\u30e3\u30c3\u30c1-8-300x169.png\" alt=\"\" width=\"300\" height=\"169\" srcset=\"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/SOFT_ASIA_\u30a2\u30a4\u30ad\u30e3\u30c3\u30c1-8-300x169.png 300w, https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/SOFT_ASIA_\u30a2\u30a4\u30ad\u30e3\u30c3\u30c1-8-1024x576.png 1024w, https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/SOFT_ASIA_\u30a2\u30a4\u30ad\u30e3\u30c3\u30c1-8-768x432.png 768w, https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/SOFT_ASIA_\u30a2\u30a4\u30ad\u30e3\u30c3\u30c1-8-1536x864.png 1536w, https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/SOFT_ASIA_\u30a2\u30a4\u30ad\u30e3\u30c3\u30c1-8.png 2048w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u521d\u5fc3\u8005\u3084\u30c7\u30fc\u30bf\u5206\u6790\u306b\u8208\u5473\u3092\u6301\u3061\u59cb\u3081\u305f\u65b9\u306b\u3068\u3063\u3066\u3001\u300c<span style=\"color: #ff0000;\"><strong>CSV\u30d5\u30a1\u30a4\u30eb\u306e\u64cd\u4f5c<\/strong><\/span>\u300d\u306f\u907f\u3051\u3066\u901a\u308c\u306a\u3044\u30b9\u30ad\u30eb\u3067\u3059\u3002\u7279\u306b<span style=\"text-decoration: underline;\"><strong>Python\u3067\u306f\u3001\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u3084\u5916\u90e8\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3063\u3066\u52b9\u7387\u3088\u304fCSV\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u66f8\u304d\u3067\u304d\u307e\u3059<\/strong><\/span>\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u672c\u8a18\u4e8b\u3067\u306f\u3001Python\u3067\u306eCSV\u30d5\u30a1\u30a4\u30eb\u64cd\u4f5c\u306e\u57fa\u790e\u304b\u3089\u5fdc\u7528\u307e\u3067\u3092\u5fb9\u5e95\u89e3\u8aac\u3057\u307e\u3059\u3002\u3055\u3089\u306b\u3001\u4eba\u6c17\u306e\u30c7\u30fc\u30bf\u5206\u6790\u30e9\u30a4\u30d6\u30e9\u30ea\u300cPandas\u300d\u3092\u7528\u3044\u305f\u5f37\u529b\u306a\u30c7\u30fc\u30bf\u64cd\u4f5c\u624b\u6cd5\u306b\u3064\u3044\u3066\u3082\u308f\u304b\u308a\u3084\u3059\u304f\u7d39\u4ecb\u3057\u307e\u3059\u3002\u3053\u308c\u3092\u8aad\u3081\u3070\u3001\u5b9f\u52d9\u3067\u3082\u4f7f\u3048\u308bCSV\u64cd\u4f5c\u304c\u30d0\u30c3\u30c1\u30ea\u8eab\u306b\u3064\u304d\u307e\u3059\u306e\u3067\u3001\u6700\u5f8c\u307e\u3067\u305c\u3072\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<div id=\"toc_container\" class=\"no_bullets\"><p class=\"toc_title\">\u76ee\u6b21<\/p><ul class=\"toc_list\"><li><a href=\"#CSV\"><span class=\"toc_number toc_depth_1\">1<\/span> CSV\u30d5\u30a1\u30a4\u30eb\u3068\u306f<\/a><\/li><li><a href=\"#PythonCSV\"><span class=\"toc_number toc_depth_1\">2<\/span> Python\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u3067CSV\u3092\u64cd\u4f5c\u3059\u308b<\/a><ul><li><a href=\"#CSV-2\"><span class=\"toc_number toc_depth_2\">2.1<\/span> CSV\u306e\u8aad\u307f\u8fbc\u307f<\/a><\/li><li><a href=\"#CSV-3\"><span class=\"toc_number toc_depth_2\">2.2<\/span> CSV\u306e\u66f8\u304d\u8fbc\u307f<\/a><\/li><li><a href=\"#DictReaderDictWriter\"><span class=\"toc_number toc_depth_2\">2.3<\/span> DictReader\/DictWriter\u3092\u4f7f\u3046<\/a><\/li><\/ul><\/li><li><a href=\"#PandasCSV\"><span class=\"toc_number toc_depth_1\">3<\/span> Pandas\u3067CSV\u3092\u64cd\u4f5c\u3059\u308b<\/a><ul><li><a href=\"#Pandas\"><span class=\"toc_number toc_depth_2\">3.1<\/span> Pandas\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/a><\/li><li><a href=\"#CSV-4\"><span class=\"toc_number toc_depth_2\">3.2<\/span> CSV\u3092\u8aad\u307f\u8fbc\u3080<\/a><\/li><li><a href=\"#CSV-5\"><span class=\"toc_number toc_depth_2\">3.3<\/span> CSV\u3092\u66f8\u304d\u51fa\u3059<\/a><\/li><li><a href=\"#i\"><span class=\"toc_number toc_depth_2\">3.4<\/span> \u30c7\u30fc\u30bf\u306e\u62bd\u51fa\u3068\u52a0\u5de5<\/a><\/li><li><a href=\"#CSV-6\"><span class=\"toc_number toc_depth_2\">3.5<\/span> CSV\u64cd\u4f5c\u3067\u3088\u304f\u3042\u308b\u30a8\u30e9\u30fc\u3068\u5bfe\u51e6\u6cd5<\/a><\/li><\/ul><\/li><li><a href=\"#i-2\"><span class=\"toc_number toc_depth_1\">4<\/span> \u5b9f\u52d9\u3067\u4f7f\u3048\u308b\u5fdc\u7528\u30c6\u30af\u30cb\u30c3\u30af<\/a><ul><li><a href=\"#CSV-7\"><span class=\"toc_number toc_depth_2\">4.1<\/span> \u8907\u6570CSV\u30d5\u30a1\u30a4\u30eb\u306e\u4e00\u62ec\u8aad\u307f\u8fbc\u307f\u30fb\u7d50\u5408<\/a><\/li><li><a href=\"#CSVmatplotlib\"><span class=\"toc_number toc_depth_2\">4.2<\/span> CSV\u30c7\u30fc\u30bf\u3092\u30b0\u30e9\u30d5\u5316\uff08matplotlib\u3068\u9023\u643a\uff09<\/a><\/li><\/ul><\/li><li><a href=\"#i-3\"><span class=\"toc_number toc_depth_1\">5<\/span> \u307e\u3068\u3081<\/a><\/li><\/ul><\/div>\n<h2><span id=\"CSV\"><span style=\"font-weight: 400;\">CSV\u30d5\u30a1\u30a4\u30eb\u3068\u306f<\/span><\/span><\/h2>\n<p><img loading=\"lazy\" class=\"size-medium wp-image-2462 aligncenter\" src=\"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/38-300x200.png\" alt=\"\" width=\"300\" height=\"200\" srcset=\"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/38-300x200.png 300w, https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/38.png 640w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\"><span style=\"text-decoration: underline;\"><strong>CSV\uff08Comma-Separated Values\uff09\u30d5\u30a1\u30a4\u30eb\u306f\u3001\u30c7\u30fc\u30bf\u3092\u30ab\u30f3\u30de\u3067\u533a\u5207\u3063\u3066\u4fdd\u5b58\u3059\u308b\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u3067\u3059<\/strong><\/span>\u3002\u884c\u3054\u3068\u306b1\u30ec\u30b3\u30fc\u30c9\u3001\u30ab\u30f3\u30de\u3054\u3068\u306b1\u30d5\u30a3\u30fc\u30eb\u30c9\u3068\u3057\u3066\u60c5\u5831\u304c\u6574\u7406\u3055\u308c\u3066\u304a\u308a\u3001\u975e\u5e38\u306b\u30b7\u30f3\u30d7\u30eb\u3067\u6271\u3044\u3084\u3059\u3044\u5f62\u5f0f\u3067\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u7279\u5fb4:<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">\u30c6\u30ad\u30b9\u30c8\u5f62\u5f0f\u306a\u306e\u3067\u8efd\u91cf<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Excel\u3084Google\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3067\u3082\u958b\u3051\u308b<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u306e\u8aad\u307f\u66f8\u304d\u304c\u5bb9\u6613<\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>\u4f8b<\/strong><\/p>\n<p><span style=\"font-weight: 400;\">CSV\u30d5\u30a1\u30a4\u30eb\u306e\u4e2d\u8eab<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u540d\u524d,\u5e74\u9f62,\u8077\u696d<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u7530\u4e2d,30,\u30a8\u30f3\u30b8\u30cb\u30a2<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u4f50\u85e4,25,\u30c7\u30b6\u30a4\u30ca\u30fc<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u9234\u6728,28,\u30de\u30fc\u30b1\u30bf\u30fc<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u3053\u306e\u3088\u3046\u306b\u3001<span style=\"color: #ff0000;\"><strong>\u30ab\u30f3\u30de\u3067\u533a\u5207\u3089\u308c\u305f\u30b7\u30f3\u30d7\u30eb\u306a\u5f62\u5f0f\u304cCSV\u306e\u7279\u5fb4<\/strong><\/span>\u3067\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u4e3b\u306a\u30e1\u30ea\u30c3\u30c8<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Excel\u3084Google\u30b9\u30d7\u30ec\u30c3\u30c9\u30b7\u30fc\u30c8\u3067\u7c21\u5358\u306b\u958b\u3051\u308b<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">\u30c6\u30ad\u30b9\u30c8\u30a8\u30c7\u30a3\u30bf\u3067\u3082\u4e2d\u8eab\u304c\u78ba\u8a8d\u3067\u304d\u308b<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">\u8efd\u91cf\u304b\u3064\u4e92\u63db\u6027\u304c\u9ad8\u3044<\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u696d\u52d9\u3067\u306f\u9867\u5ba2\u30c7\u30fc\u30bf\u3001\u58f2\u4e0a\u30c7\u30fc\u30bf\u3001\u5546\u54c1\u30ea\u30b9\u30c8\u306a\u3069\u3001\u591a\u304f\u306e\u60c5\u5831\u3092CSV\u5f62\u5f0f\u3067\u3084\u308a\u53d6\u308a\u3059\u308b\u6a5f\u4f1a\u304c\u3042\u308a\u307e\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2><span id=\"PythonCSV\"><span style=\"font-weight: 400;\">Python\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u3067CSV\u3092\u64cd\u4f5c\u3059\u308b<\/span><\/span><\/h2>\n<p><img loading=\"lazy\" class=\"size-medium wp-image-2463 aligncenter\" src=\"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/39-300x200.png\" alt=\"\" width=\"300\" height=\"200\" srcset=\"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/39-300x200.png 300w, https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/39.png 640w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\"><span style=\"text-decoration: underline;\"><strong>Python\u306b\u306f\u6a19\u6e96\u3067csv\u30e2\u30b8\u30e5\u30fc\u30eb\u304c\u7528\u610f\u3055\u308c\u3066\u304a\u308a\u3001\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u4e0d\u8981\u3067CSV\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u66f8\u304d\u304c\u53ef\u80fd\u3067\u3059<\/strong><\/span>\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><span id=\"CSV-2\"><span style=\"font-weight: 400;\">CSV\u306e\u8aad\u307f\u8fbc\u307f<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400; color: #3366ff;\">import csv<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">with open(&#8216;sample.csv&#8217;, newline=&#8221;, encoding=&#8217;utf-8&#8242;) as f:<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">\u00a0\u00a0\u00a0\u00a0reader = csv.reader(f)<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">\u00a0\u00a0\u00a0\u00a0for row in reader:<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0print(row)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u3053\u306e\u30b3\u30fc\u30c9\u3067\u30011\u884c\u305a\u3064\u30ea\u30b9\u30c8\u5f62\u5f0f\u3067\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3067\u304d\u307e\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><span id=\"CSV-3\"><span style=\"font-weight: 400;\">CSV\u306e\u66f8\u304d\u8fbc\u307f<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400; color: #3366ff;\">import csv<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">data = [<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">\u00a0\u00a0\u00a0\u00a0[&#8220;Name&#8221;, &#8220;Age&#8221;, &#8220;Country&#8221;],<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">\u00a0\u00a0\u00a0\u00a0[&#8220;Alice&#8221;, 25, &#8220;USA&#8221;],<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">\u00a0\u00a0\u00a0\u00a0[&#8220;Bob&#8221;, 30, &#8220;UK&#8221;]<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">]<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">with open(&#8216;output.csv&#8217;, &#8216;w&#8217;, newline=&#8221;, encoding=&#8217;utf-8&#8242;) as f:<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">\u00a0\u00a0\u00a0\u00a0writer = csv.writer(f)<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">\u00a0\u00a0\u00a0\u00a0writer.writerows(data)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><strong>\u30ef\u30f3\u30dd\u30a4\u30f3\u30c8<\/strong><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">newline=&#8221; \u3092\u4f7f\u3046\u3053\u3068\u3067\u3001Windows\u74b0\u5883\u3067\u4e0d\u8981\u306a\u7a7a\u884c\u304c\u51fa\u308b\u306e\u3092\u9632\u304e\u307e\u3059\u3002<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">encoding=&#8217;utf-8&#8242; \u306f\u65e5\u672c\u8a9e\u3092\u6b63\u3057\u304f\u6271\u3046\u305f\u3081\u306b\u91cd\u8981\u3067\u3059<\/span><span style=\"font-weight: 400;\">\u3002<\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h3><span id=\"DictReaderDictWriter\"><span style=\"font-weight: 400;\">DictReader\/DictWriter\u3092\u4f7f\u3046<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400; color: #3366ff;\">import csv<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">with open(&#8216;sample.csv&#8217;, newline=&#8221;, encoding=&#8217;utf-8&#8242;) as csvfile:<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">\u00a0\u00a0\u00a0\u00a0reader = csv.DictReader(csvfile)<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">\u00a0\u00a0\u00a0\u00a0for row in reader:<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0print(row[&#8216;\u540d\u524d&#8217;], row[&#8216;\u5e74\u9f62&#8217;])<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u8f9e\u66f8\u5f62\u5f0f\u3067\u6271\u3048\u308b\u305f\u3081\u3001\u53ef\u8aad\u6027\u30fb\u30e1\u30f3\u30c6\u30ca\u30f3\u30b9\u6027\u304c\u9ad8\u304f\u306a\u308a\u307e\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2><span id=\"PandasCSV\"><span style=\"font-weight: 400;\">Pandas\u3067CSV\u3092\u64cd\u4f5c\u3059\u308b<\/span><\/span><\/h2>\n<p><img loading=\"lazy\" class=\"size-medium wp-image-2464 aligncenter\" src=\"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/40-300x200.png\" alt=\"\" width=\"300\" height=\"200\" srcset=\"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/40-300x200.png 300w, https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/40.png 640w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">Pandas\u306f\u30c7\u30fc\u30bf\u5206\u6790\u306e\u305f\u3081\u306b\u5e83\u304f\u4f7f\u308f\u308c\u308bPython\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u3002<span style=\"text-decoration: underline;\"><strong>\u8868\u5f62\u5f0f\u306e\u30c7\u30fc\u30bf\uff08DataFrame\uff09\u3068\u3057\u3066CSV\u30d5\u30a1\u30a4\u30eb\u3092\u6271\u3046\u3053\u3068\u304c\u3067\u304d\u3001Excel\u30e9\u30a4\u30af\u306a\u611f\u899a\u3067\u64cd\u4f5c\u3067\u304d\u307e\u3059<\/strong><\/span>\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><span id=\"Pandas\"><span style=\"font-weight: 400;\">Pandas\u306e\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400; color: #3366ff;\">pip install pandas<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><span id=\"CSV-4\"><span style=\"font-weight: 400;\">CSV\u3092\u8aad\u307f\u8fbc\u3080<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400; color: #3366ff;\">import pandas as pd<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">df = pd.read_csv(&#8216;sample.csv&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">print(df)<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><span id=\"CSV-5\"><span style=\"font-weight: 400;\">CSV\u3092\u66f8\u304d\u51fa\u3059<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400; color: #3366ff;\">df.to_csv(&#8216;output.csv&#8217;, index=False, encoding=&#8217;utf-8&#8242;)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">index=False\u3092\u6307\u5b9a\u3057\u306a\u3044\u3068\u3001\u81ea\u52d5\u3067\u884c\u756a\u53f7\uff08\u30a4\u30f3\u30c7\u30c3\u30af\u30b9\uff09\u304cCSV\u306b\u8ffd\u52a0\u3055\u308c\u3066\u3057\u307e\u3046\u306e\u3067\u6ce8\u610f\u3057\u307e\u3057\u3087\u3046\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><span id=\"i\"><span style=\"font-weight: 400;\">\u30c7\u30fc\u30bf\u306e\u62bd\u51fa\u3068\u52a0\u5de5<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400;\"><span style=\"color: #3366ff;\">print(df[&#8216;\u540d\u524d&#8217;])<\/span> \u00a0 \u00a0 \u00a0 \u00a0 # \u7279\u5b9a\u306e\u5217\u3092\u62bd\u51fa<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><span style=\"color: #3366ff;\">print(df.iloc[0])<\/span> \u00a0 \u00a0 \u00a0 \u00a0 # 1\u884c\u76ee\u3092\u62bd\u51fa<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><span style=\"color: #3366ff;\">df[&#8216;\u5e74\u9f62&#8217;] += 1<\/span> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 # \u5e74\u9f62\u30921\u6b73\u52a0\u7b97<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><span style=\"color: #3366ff;\">df[&#8216;\u8077\u696d&#8217;] = df[&#8216;\u8077\u696d&#8217;].str.upper()<\/span>\u00a0 # \u8077\u696d\u3092\u5927\u6587\u5b57\u306b\u5909\u63db<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><span style=\"color: #3366ff;\">filtered = df[df[&#8216;\u5e74\u9f62&#8217;] &gt; 30]<\/span>\u00a0 # 30\u6b73\u4ee5\u4e0a\u306e\u30c7\u30fc\u30bf\u62bd\u51fa<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">print(filtered)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>\u5177\u4f53\u7684\u306a\u6d3b\u7528\u4f8b<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">\u9867\u5ba2\u306e\u8a95\u751f\u65e5\u304b\u3089\u5e74\u9f62\u3092\u81ea\u52d5\u8a08\u7b97<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">\u5546\u54c1\u30c7\u30fc\u30bf\u304b\u3089\u5728\u5eab\u30bc\u30ed\u306e\u5546\u54c1\u3092\u62bd\u51fa<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">\u58f2\u4e0a\u30c7\u30fc\u30bf\u304b\u3089\u5e97\u8217\u5225\u30fb\u6708\u5225\u306e\u96c6\u8a08\u3092\u4f5c\u6210<\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h3><span id=\"CSV-6\"><span style=\"font-weight: 400;\">CSV\u64cd\u4f5c\u3067\u3088\u304f\u3042\u308b\u30a8\u30e9\u30fc\u3068\u5bfe\u51e6\u6cd5<\/span><\/span><\/h3>\n<p><img loading=\"lazy\" class=\"size-medium wp-image-2467 aligncenter\" src=\"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/SOFT-_ASIA-34-300x200.png\" alt=\"\" width=\"300\" height=\"200\" srcset=\"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/SOFT-_ASIA-34-300x200.png 300w, https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/SOFT-_ASIA-34.png 640w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><b>UnicodeDecodeError\uff08\u6587\u5b57\u30b3\u30fc\u30c9\u30a8\u30e9\u30fc\uff09<\/b><\/p>\n<p><span style=\"font-weight: 400;\">\u539f\u56e0\uff1aCSV\u30d5\u30a1\u30a4\u30eb\u306e\u6587\u5b57\u30b3\u30fc\u30c9\u304cUTF-8\u4ee5\u5916\uff08\u4f8b\uff1aShift-JIS\uff09<\/span><\/p>\n<p><span style=\"font-weight: 400;\">\u5bfe\u51e6\u6cd5\uff1aencoding\u3092\u6307\u5b9a\u3059\u308b<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">df = pd.read_csv(&#8216;sample.csv&#8217;, encoding=&#8217;shift_jis&#8217;)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>FileNotFoundError\uff08\u30d5\u30a1\u30a4\u30eb\u304c\u898b\u3064\u304b\u3089\u306a\u3044\uff09<\/b><\/p>\n<p><span style=\"font-weight: 400;\">\u5bfe\u51e6\u6cd5\uff1a\u30d5\u30a1\u30a4\u30eb\u30d1\u30b9\u3092\u78ba\u8a8d\u3059\u308b\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">import os<\/span><\/p>\n<p><span style=\"font-weight: 400;\"><span style=\"color: #3366ff;\">print(os.getcwd())<\/span>\u00a0 # \u73fe\u5728\u306e\u4f5c\u696d\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u8868\u793a<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b>index\u5217\u304c\u81ea\u52d5\u3067\u8ffd\u52a0\u3055\u308c\u308b<\/b><\/p>\n<p><span style=\"font-weight: 400;\">\u5bfe\u51e6\u6cd5\uff1a\u66f8\u304d\u51fa\u3057\u6642\u306bindex=False\u3092\u660e\u793a<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">df.to_csv(&#8216;output.csv&#8217;, index=False)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u30d5\u30a1\u30a4\u30eb\u306e\u30a8\u30f3\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3084\u30d1\u30b9\u6307\u5b9a\u306f\u3001\u521d\u5fc3\u8005\u304c\u3064\u307e\u305a\u304d\u3084\u3059\u3044\u30dd\u30a4\u30f3\u30c8\u3067\u3059\u3002<span style=\"text-decoration: underline;\"><strong>\u5e38\u306btry-except\u69cb\u6587\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001\u30a8\u30e9\u30fc\u6642\u306e\u5bfe\u5fdc\u304c\u67d4\u8edf\u306b\u306a\u308a\u307e\u3059<\/strong><\/span>\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2><span id=\"i-2\"><span style=\"font-weight: 400;\">\u5b9f\u52d9\u3067\u4f7f\u3048\u308b\u5fdc\u7528\u30c6\u30af\u30cb\u30c3\u30af<\/span><\/span><\/h2>\n<p><img loading=\"lazy\" class=\"alignnone size-medium wp-image-2465 aligncenter\" src=\"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/41-300x200.png\" alt=\"\" width=\"300\" height=\"200\" srcset=\"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/41-300x200.png 300w, https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/41.png 640w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>&nbsp;<\/p>\n<h3><span id=\"CSV-7\"><span style=\"font-weight: 400;\">\u8907\u6570CSV\u30d5\u30a1\u30a4\u30eb\u306e\u4e00\u62ec\u8aad\u307f\u8fbc\u307f\u30fb\u7d50\u5408<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400; color: #3366ff;\">import glob<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">import pandas as pd<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">files = glob.glob(&#8216;data\/*.csv&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">df_list = [pd.read_csv(file) for file in files]<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">combined_df = pd.concat(df_list, ignore_index=True)<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u3053\u306e\u30b3\u30fc\u30c9\u306f\u3001\u7279\u5b9a\u30d5\u30a9\u30eb\u30c0\u5185\u306eCSV\u30d5\u30a1\u30a4\u30eb\u3092\u3059\u3079\u3066\u7d50\u5408\u3057\u3001\u4e00\u3064\u306e\u5927\u304d\u306aDataFrame\u3068\u3057\u3066\u6271\u3044\u307e\u3059\u3002\u5e74\u9593\u306e\u58f2\u4e0a\u30d5\u30a1\u30a4\u30eb\uff08\u6708\u5225\uff09\u3092\u7d71\u5408\u3057\u305f\u3044\u6642\u306a\u3069\u306b\u4fbf\u5229\u3067\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h3><span id=\"CSVmatplotlib\"><span style=\"font-weight: 400;\">CSV\u30c7\u30fc\u30bf\u3092\u30b0\u30e9\u30d5\u5316\uff08matplotlib\u3068\u9023\u643a\uff09<\/span><\/span><\/h3>\n<p><span style=\"font-weight: 400; color: #3366ff;\">import matplotlib.pyplot as plt<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">df.plot(x=&#8217;\u540d\u524d&#8217;, y=&#8217;\u5e74\u9f62&#8217;, kind=&#8217;bar&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">plt.title(&#8216;\u5e74\u9f62\u5225\u68d2\u30b0\u30e9\u30d5&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">plt.xlabel(&#8216;\u540d\u524d&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">plt.ylabel(&#8216;\u5e74\u9f62&#8217;)<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">plt.grid(True)<\/span><\/p>\n<p><span style=\"font-weight: 400; color: #3366ff;\">plt.show()<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u58f2\u4e0a\u63a8\u79fb\u306e\u6298\u308c\u7dda\u30b0\u30e9\u30d5\u3084\u3001\u5546\u54c1\u30ab\u30c6\u30b4\u30ea\u3054\u3068\u306e\u5186\u30b0\u30e9\u30d5\u306a\u3069\u3082\u7c21\u5358\u306b\u4f5c\u6210\u3067\u304d\u307e\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<h2><span id=\"i-3\"><span style=\"font-weight: 400;\">\u307e\u3068\u3081<\/span><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Python\u3067CSV\u30d5\u30a1\u30a4\u30eb\u3092\u64cd\u4f5c\u3059\u308b\u30b9\u30ad\u30eb\u306f\u3001\u30c7\u30fc\u30bf\u5206\u6790\u3084\u696d\u52d9\u81ea\u52d5\u5316\u3092\u76ee\u6307\u3059\u4e0a\u3067\u975e\u5e38\u306b\u91cd\u8981\u3067\u3059\u3002\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3082\u57fa\u672c\u7684\u306a\u64cd\u4f5c\u306f\u53ef\u80fd\u3067\u3059\u304c\u3001Pandas\u3092\u4f7f\u3048\u3070\u3088\u308a\u52b9\u7387\u7684\u3067\u9ad8\u6a5f\u80fd\u306a\u51e6\u7406\u304c\u53ef\u80fd\u306b\u306a\u308a\u307e\u3059\u3002<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-weight: 400;\">\u3053\u306e\u8a18\u4e8b\u306e\u307e\u3068\u3081<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">CSV\u30d5\u30a1\u30a4\u30eb\u306f\u3042\u3089\u3086\u308b\u5834\u9762\u3067\u4f7f\u308f\u308c\u308b\u57fa\u672c\u7684\u306a\u30c7\u30fc\u30bf\u5f62\u5f0f<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Python\u306ecsv\u30e2\u30b8\u30e5\u30fc\u30eb\u3067\u8aad\u307f\u66f8\u304d\u306f\u7c21\u5358\u306b\u3067\u304d\u308b<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Pandas\u3092\u4f7f\u3048\u3070\u3001\u30c7\u30fc\u30bf\u52a0\u5de5\u30fb\u96c6\u8a08\u30fb\u53ef\u8996\u5316\u304c\u5727\u5012\u7684\u306b\u697d\u306b\u306a\u308b<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">\u5b9f\u52d9\u3067\u3082\u4f7f\u3048\u308b\u4e00\u62ec\u51e6\u7406\u3084\u53ef\u8996\u5316\u30c6\u30af\u30cb\u30c3\u30af\u3092\u6d3b\u7528\u3057\u3088\u3046<\/span><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>\u4eca\u5f8c\u3001CSV\u3060\u3051\u3067\u306a\u304fExcel\u3084JSON\u3001SQL\u306a\u3069\u4ed6\u5f62\u5f0f\u306e\u30c7\u30fc\u30bf\u3082\u6271\u3046\u6a5f\u4f1a\u304c\u5897\u3048\u3066\u304d\u307e\u3059\u3002\u307e\u305a\u306fCSV\u306e\u57fa\u672c\u3092\u3057\u3063\u304b\u308a\u62bc\u3055\u3048\u3066\u3001\u6b21\u306e\u30b9\u30c6\u30c3\u30d7\u306b\u9032\u307f\u307e\u3057\u3087\u3046\u3002\u3082\u3057\u3001\u3088\u308a\u8907\u96d1\u306a\u30c7\u30fc\u30bf\u51e6\u7406\u3084\u696d\u52d9\u306e\u81ea\u52d5\u5316\u3067\u304a\u56f0\u308a\u3067\u3057\u305f\u3089\u3001\u304a\u6c17\u8efd\u306b<span style=\"color: #0000ff;\"><strong><a style=\"color: #0000ff;\" href=\"https:\/\/softasia.jp\/#contact\">3ink<\/a><\/strong><\/span>\u3078\u3054\u76f8\u8ac7\u304f\u3060\u3055\u3044\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; \u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u521d\u5fc3\u8005\u3084\u30c7\u30fc\u30bf\u5206\u6790\u306b\u8208\u5473\u3092\u6301\u3061\u59cb\u3081\u305f\u65b9\u306b\u3068\u3063\u3066\u3001\u300cCSV\u30d5\u30a1\u30a4\u30eb\u306e\u64cd\u4f5c\u300d\u306f\u907f\u3051\u3066\u901a\u308c\u306a\u3044\u30b9\u30ad\u30eb\u3067\u3059\u3002\u7279\u306bPython\u3067\u306f\u3001\u6a19\u6e96\u30e9\u30a4\u30d6\u30e9\u30ea\u3084\u5916\u90e8\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u3063\u3066\u52b9\u7387\u3088\u304fCSV\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u66f8\u304d [&hellip;]<\/p>\n","protected":false},"author":9,"featured_media":2458,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false},"categories":[1,9],"tags":[],"jetpack_featured_media_url":"https:\/\/softasia.jp\/blog\/wp-content\/uploads\/2025\/08\/SOFT_ASIA_\u30a2\u30a4\u30ad\u30e3\u30c3\u30c1-8.png","_links":{"self":[{"href":"https:\/\/softasia.jp\/blog\/wp-json\/wp\/v2\/posts\/2411"}],"collection":[{"href":"https:\/\/softasia.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/softasia.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/softasia.jp\/blog\/wp-json\/wp\/v2\/users\/9"}],"replies":[{"embeddable":true,"href":"https:\/\/softasia.jp\/blog\/wp-json\/wp\/v2\/comments?post=2411"}],"version-history":[{"count":20,"href":"https:\/\/softasia.jp\/blog\/wp-json\/wp\/v2\/posts\/2411\/revisions"}],"predecessor-version":[{"id":2807,"href":"https:\/\/softasia.jp\/blog\/wp-json\/wp\/v2\/posts\/2411\/revisions\/2807"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/softasia.jp\/blog\/wp-json\/wp\/v2\/media\/2458"}],"wp:attachment":[{"href":"https:\/\/softasia.jp\/blog\/wp-json\/wp\/v2\/media?parent=2411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softasia.jp\/blog\/wp-json\/wp\/v2\/categories?post=2411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softasia.jp\/blog\/wp-json\/wp\/v2\/tags?post=2411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}