{"id":4300,"date":"2024-01-02T22:28:35","date_gmt":"2024-01-02T13:28:35","guid":{"rendered":"https:\/\/jfs.or.jp\/jfs-cs\/?p=4300"},"modified":"2024-05-17T09:41:29","modified_gmt":"2024-05-17T00:41:29","slug":"python-polars-01","status":"publish","type":"post","link":"https:\/\/jfs.or.jp\/jfs-cs\/python-polars-01\/","title":{"rendered":"\u30d7\u30ed\u30b0\u30e9\u30e0\u8a00\u8a9e\u3000Python\u306e\u30e2\u30b8\u30e5\u30fc\u30eb polars\uff08\u767d\u718a\uff09\u306e\u7d39\u4ecb"},"content":{"rendered":"<p>Python\u306f\u3001\u8a18\u8ff0\u304c\u89e3\u308a\u3084\u3059\u304f\u30b3\u30f3\u30d1\u30a4\u30eb\u4e0d\u8981\u3067\u4f7f\u3048\u308b\u3053\u3068\u304c\u8a55\u4fa1\u3055\u308c\u3001\u5927\u898f\u6a21\u958b\u767a\u306b\u3082\u5229\u7528\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u4e00\u65b9\u3001\u5b9f\u52d9\u3067\u4f7f\u3046\u3053\u3068\u304c\u591a\u3044\u30a8\u30af\u30bb\u30eb\u3084\u8868\u5f62\u5f0f\u30c7\u30fc\u30bf\u3092\u53d6\u308a\u6271\u3046\u306b\u306f\u3001Python\u306e\u62e1\u5f35\u30e2\u30b8\u30e5\u30fc\u30eb\u306eNumpy\u3068\u304bPandas\u3068\u3044\u3063\u305f\u30a2\u30d7\u30ea\u304c\u4f7f\u308f\u308c\u3066\u304d\u307e\u3057\u305f\u304c\u3001\u3053\u30531\u5e74\u307b\u3069\u3067\u767b\u5834\u3057\u305d\u306e\u9ad8\u901f\u6027\u3068\u6271\u3044\u3084\u3059\u3055\u3067\u6025\u6fc0\u306b\u666e\u53ca\u3057\u306f\u3058\u3081\u305f\u306e\u304c\u3000polars\uff08\u3057\u308d\u304f\u307e\uff09\u3060\u3068\u3002\u7279\u306b\u5927\u91cf\u30c7\u30fc\u30bf\u3092\u53d6\u308a\u6271\u3046\u3068\u304d\u306b\u3001\u305d\u306e\u901f\u3055\u304c\u969b\u7acb\u3063\u3066\u308b\u3088\u3046\u3067\u3059\u3002IoT\u3067\u306f\u3001\u5f97\u3089\u308c\u308b\u30c7\u30fc\u30bf\u91cf\u304c\u6975\u3081\u3066\u591a\u3044\u306e\u304c\u7279\u5fb4\u306a\u306e\u3067\u3001\u3053\u306e\u7279\u6027\u306f\u91cd\u8981\u3060\u3068\u601d\u3048\u307e\u3059\u3002<\/p>\n<p><span style=\"color: #0000ff;\"><strong>\u5143\u30c7\u30fc\u30bf\u5185\u5bb9\u306f\u305d\u306e\u307e\u307e\u3067\u3001\u4eee\u60f3\u7684\u306b\u69d8\u3005\u306a\u5206\u6790\u304c\u3067\u304d\u307e\u3059\u3002<br \/>\n<\/strong><\/span><span style=\"color: #0000ff;\"><strong>\u30a8\u30af\u30bb\u30eb\u306f\u3001\u5408\u8a08\u884c\u8ffd\u52a0\u3084\u5217\u306e\u975e\u8868\u793a\u3067\u5143\u306e\u59ff\u304c\u5909\u5316\u3057\u3066\u3057\u307e\u3046\u3002<\/strong><\/span><\/p>\n<p>\u30a8\u30af\u30bb\u30eb\u3067\u306f\u96e3\u3057\u3044\u300c\u5546\u54c1\u30de\u30b9\u30bf\u30fc\u300d\u3068\u300c\u58f2\u308a\u4e0a\u3052\u300d\u30d5\u30a1\u30a4\u30eb\u3092\u3001\u30ad\u30fc\u9805\u76ee\u3067\u30ea\u30f3\u30af\u3059\u308b\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u7684\u306a\u5229\u7528\u3082\u7c21\u5358\u3002<\/p>\n<p>\u82f1\u8a9e\u306e\u672c\u5bb6\u304c\u3053\u3061\u3089\u3000<span style=\"font-size: 16px;\"><strong><a href=\"https:\/\/pola.rs\/\">https:\/\/pola.rs\/<\/a><\/strong><\/span><\/p>\n<p class=\"eyebrow color-polars-earth\"><span style=\"font-size: 16px;\"><strong>WHY USE POLARS\u3000\uff08\u306a\u305c\u3000POLARS \u3092\u4f7f\u3046\u306e\uff1f\uff09<\/strong><\/span><\/p>\n<p>\u3000Polars was benchmarked against several other solutions on the independent TPCH Benchmark. This benchmark aims to replicate data wrangling operations used in practice. Polars easily trumps other solutions due to its parallel execution engine, efficient algorithms and use of vectorization with SIMD (Single Instruction, Multiple Data). Compared to pandas, it can achieve more than 30x performance gains.<\/p>\n<p>\uff08\u4e0a\u8a18\u8aac\u660e\u306e\u7ffb\u8a33\uff09<br \/>\n\u3000Polars \u306f\u3001\u72ec\u7acb\u3057\u305f TPCH \u30d9\u30f3\u30c1\u30de\u30fc\u30af\u3067\u4ed6\u306e\u3044\u304f\u3064\u304b\u306e\u30bd\u30ea\u30e5\u30fc\u30b7\u30e7\u30f3\u306b\u5bfe\u3057\u3066\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u304c\u884c\u308f\u308c\u307e\u3057\u305f\u3002 \u3053\u306e\u30d9\u30f3\u30c1\u30de\u30fc\u30af\u306f\u3001\u5b9f\u969b\u306b\u4f7f\u7528\u3055\u308c\u308b\u30c7\u30fc\u30bf \u30e9\u30f3\u30b0\u30ea\u30f3\u30b0\u64cd\u4f5c\u3092\u518d\u73fe\u3059\u308b\u3053\u3068\u3092\u76ee\u7684\u3068\u3057\u3066\u3044\u307e\u3059\u3002 Polars \u306f\u3001\u4e26\u5217\u5b9f\u884c\u30a8\u30f3\u30b8\u30f3\u3001\u52b9\u7387\u7684\u306a\u30a2\u30eb\u30b4\u30ea\u30ba\u30e0\u3001SIMD (\u5358\u4e00\u547d\u4ee4\u3001\u8907\u6570\u30c7\u30fc\u30bf) \u306b\u3088\u308b\u30d9\u30af\u30c8\u30eb\u5316\u306e\u4f7f\u7528\u306b\u3088\u308a\u3001\u4ed6\u306e\u30bd\u30ea\u30e5\u30fc\u30b7\u30e7\u30f3\u3092\u5bb9\u6613\u306b\u4e0a\u56de\u308a\u307e\u3059\u3002<span style=\"color: #0000ff;\"><strong> pandas \u3068\u6bd4\u8f03\u3057\u3066\u300130 \u500d\u4ee5\u4e0a\u306e\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u5411\u4e0a\u3092\u9054\u6210\u3067\u304d\u307e\u3059\u3002<\/strong><\/span><\/p>\n<p>\n<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"https:\/\/pola.rs\/_astro\/perf-illustration.5c2f97d2_Z1N47TN.svg\" alt=\"Performance illustration\" width=\"566\" height=\"570\" \/><\/p>\n<p>\n\u51fa\u6765\u305f\u3070\u304b\u308a\u3067\u3001Update\u304c\u983b\u7e41\u306b\u884c\u308f\u308c\u3066\u3044\u308b\u306e\u3067\u3001\u6700\u65b0\u7248\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u3092\u304a\u52e7\u3081\u3057\u307e\u3059\u3002<br \/>\n<span style=\"color: #0000ff;\"><strong>\u672c\u5bb6\u306e\u6a5f\u80fd\u7d39\u4ecb\u30b5\u30a4\u30c8<\/strong><\/span>\u3000<a href=\"https:\/\/docs.pola.rs\/py-polars\/html\/reference\/index.html\">https:\/\/docs.pola.rs\/py-polars\/html\/reference\/index.html<\/a><br \/>\n\u82f1\u8a9e\u306e\u672c\u5bb6\u30b5\u30a4\u30c8\u3067\u306f\u3001\u5404\u6a5f\u80fd\u3068\u4f7f\u3044\u65b9\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u304c\u4e01\u5be7\u306b\u66f8\u304b\u308c\u3066\u3044\u3066\u3001\u305d\u308c\u3060\u3051\u3067\u3082\u5341\u5206\u306b\u4f7f\u3044\u65b9\u304c\u89e3\u308a\u307e\u3059\u3002<\/p>\n<p>\u4e00\u65b9\u30012023\u5e74\u5f8c\u534a\u304b\u3089\u3001\u65e5\u672c\u8a9e\u306e\u7d39\u4ecb\u30b5\u30a4\u30c8\u304c\u51fa\u59cb\u3081\u307e\u3057\u305f\u3002\u6700\u65b0\u3067\u306f\u3001\u4e0b\u8a18\u306e\u30b5\u30a4\u30c8\u304c\u89e3\u308a\u3084\u3059\u3044\u3002\u30a4\u30e1\u30fc\u30b8\u3057\u3084\u3059\u3044\u3054\u304f\u5165\u9580\u90e8\u5206\u3092\u5f15\u7528\u3054\u7d39\u4ecb\u3002\u30b5\u30a4\u30c8\u3067\u306f\u3001\u901a\u5e38\u51fa\u4f1a\u3046\u5834\u9762\u306e\u304b\u306a\u308a\u306e\u5834\u5408\u306e\u89e3\u8aac\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u3000<a href=\"https:\/\/qiita.com\/_jinta\">@_jinta<\/a>\u3000\u6c0f\u306e\u89e3\u8aac\u30b5\u30a4\u30c8\u306e\u6982\u8981\u90e8\u5206\u3067\u3059\u3002<\/p>\n<h2 class=\"style-wo2a1i\" data-logly-title=\"true\"><a href=\"https:\/\/qiita.com\/_jinta\/items\/fac13f09e8e8a5769b79\">\u8d85\u9ad8\u901f\u2026\u3060\u3051\u3058\u3083\u306a\u3044\uff01Pandas\u306b\u4ee3\u3048\u3066Polars\u3092\u4f7f\u3044\u305f\u3044\u7406\u7531<\/a><\/h2>\n<ul class=\"style-ee2v6o\">\n<li><a class=\"style-1eh008r\" href=\"https:\/\/qiita.com\/tags\/polars\">Polars<\/a><\/li>\n<\/ul>\n<div class=\"style-1npej5s\"><span class=\"style-1mp27y1\">\u6700\u7d42\u66f4\u65b0\u65e5\u00a0<time datetime=\"2023-11-05T15:22:03Z\">2023\u5e7411\u670806\u65e5<\/time><\/span><span class=\"style-1mp27y1\">\u6295\u7a3f\u65e5\u00a02022\u5e7412\u670805\u65e5<\/span><\/div>\n<section class=\"it-MdContent darkMode\">\n<p data-sourcepos=\"2:1-2:245\"><strong>Polars\u3068\u3044\u3046Pandas\u3092100\u500d\u304f\u3089\u3044\u9ad8\u6027\u80fd\u306b\u3057\u305f\u30e9\u30a4\u30d6\u30e9\u30ea<\/strong>\u304c\u3068\u3066\u3082\u826f\u3044\u306e\u3067\u5e03\u6559\u3057\u307e\u3059<sup><a id=\"fnref-100\" href=\"https:\/\/qiita.com\/_jinta\/items\/fac13f09e8e8a5769b79#fn-100\">1<\/a><\/sup>\u3002Polars\u306fRust\u30d9\u30fc\u30b9\u306eDataFrame\u30e9\u30a4\u30d6\u30e9\u30ea\u3067\u3059\u304c\u3001\u672c\u8a18\u4e8b\u3067\u306fPython\u3067\u306e\u305d\u308c\u306b\u3064\u3044\u3066\u8a9e\u308a\u307e\u3059\u3002<br \/>\n\u3061\u306a\u307f\u306bpolars\u306f\u767d\u718a\u306e\u610f\u3067\u3059\u3002\u305d\u308a\u3083\u3042\u307e\u3042\u3001<strong>\u767d\u718a\u3068\u5927\u718a\u732b\u6bd4\u3079\u305f\u3089\u767d\u718a\u306e\u307b\u3046\u304c\u901f\u3044\u3057\u5f37\u3044\u3088\u306d<\/strong>\u3063\u3066\u3053\u3068\u3067\u3059<sup><a id=\"fnref-pronounce\" href=\"https:\/\/qiita.com\/_jinta\/items\/fac13f09e8e8a5769b79#fn-pronounce\">2<\/a><\/sup>\u3002<\/p>\n<h3 data-sourcepos=\"53:1-53:22\">\u30dd\u30a4\u30f3\u30c8\uff1a\u30003. \u66f8\u304d\u3084\u3059\u3044<\/h3>\n<p data-sourcepos=\"55:1-55:226\">\u5b9f\u306f\u3053\u308c\u304c\u4e00\u756a\u306e\u63a8\u3057\u30dd\u30a4\u30f3\u30c8\u3067\u3059\u304c\u3001\u3042\u307e\u308a\u8a9e\u3089\u308c\u308b\u3053\u3068\u304c\u591a\u304f\u306a\u3044\u6c17\u304c\u3057\u307e\u3059\u3002\u3068\u3044\u3046\u3053\u3068\u3067\u3001<strong>\u3053\u306e\u8a18\u4e8b\u3067\u306fPolars\u306e\u66f8\u304d\u3084\u3059\u3055\u306e\u8a71\u3092\u30e1\u30a4\u30f3\u3067\u3057\u3066\u3044\u304d\u307e\u3059\uff01\uff01<br \/>\n<\/strong>\u2026\u2026\u306e\u524d\u306b\u307e\u305a\u3001\u6982\u8981\u7684\u306a\u3068\u3053\u308d\u3092\u7c21\u5358\u306b\u7d39\u4ecb\u3057\u307e\u3057\u3087\u3046\u3002<\/p>\n<h1 data-sourcepos=\"60:1-60:14\">Polars\u5165\u9580<\/h1>\n<h2 data-sourcepos=\"61:1-61:29\">10\u884c\u3067\u628a\u63e1\u3059\u308bPolars<\/h2>\n<p data-sourcepos=\"62:1-62:76\">iris\u30c7\u30fc\u30bf\u30bb\u30c3\u30c8\u3092\u4f8b\u306b\u9069\u5f53\u306a\u51e6\u7406\u3092\u66f8\u3044\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br \/>\n\u30c7\u30fc\u30bf\u9805\u76ee\u306f\u3001[&#8216;sepal_length&#8217;, &#8216;sepal_width&#8217;, &#8216;petal_length&#8217;, &#8216;petal_width&#8217;, &#8216;species&#8217;]\u3067\u3059\u3002<br \/>\n\u3053\u308c\u306b\u5bfe\u3057\u3066<\/p>\n<pre><code>\r\n<span class=\"kn\">import<\/span> <span class=\"n\">polars<\/span> <span class=\"k\">as<\/span> <span class=\"n\">pl<\/span>\r\n<span class=\"n\">df<\/span> <span class=\"o\">=<\/span> <span class=\"n\">pl<\/span><span class=\"p\">.<\/span><span class=\"nf\">read_csv<\/span><span class=\"p\">(<\/span><span class=\"sh\">\"<\/span><span class=\"s\">https:\/\/j.mp\/iriscsv<\/span><span class=\"sh\">\"<\/span><span class=\"p\">)<\/span>                         <span class=\"c1\"># \u30c7\u30fc\u30bf\u8aad\u307f\u8fbc\u307f\r\n<\/span><span class=\"n\">df_agg<\/span> <span class=\"o\">=<\/span> <span class=\"p\">(<\/span>\r\n    <span class=\"n\">df<\/span>\r\n    <span class=\"p\">.<\/span><span class=\"nf\">select<\/span><span class=\"p\">([<\/span><span class=\"n\">pl<\/span><span class=\"p\">.<\/span><span class=\"nf\">col<\/span><span class=\"p\">(<\/span><span class=\"sh\">\"<\/span><span class=\"s\">^sepal_.*$<\/span><span class=\"sh\">\"<\/span><span class=\"p\">),<\/span> <span class=\"n\">pl<\/span><span class=\"p\">.<\/span><span class=\"nf\">col<\/span><span class=\"p\">(<\/span><span class=\"sh\">\"<\/span><span class=\"s\">species<\/span><span class=\"sh\">\"<\/span><span class=\"p\">)])<\/span>           <span class=\"c1\"># \u5217\u306e\u9078\u629e\r\n<\/span>    <span class=\"p\">.<\/span><span class=\"nf\">with_columns<\/span><span class=\"p\">((<\/span><span class=\"n\">pl<\/span><span class=\"p\">.<\/span><span class=\"nf\">col<\/span><span class=\"p\">(<\/span><span class=\"sh\">\"<\/span><span class=\"s\">sepal_width<\/span><span class=\"sh\">\"<\/span><span class=\"p\">)<\/span> <span class=\"o\">*<\/span> <span class=\"mi\">2<\/span><span class=\"p\">).<\/span><span class=\"nf\">alias<\/span><span class=\"p\">(<\/span><span class=\"sh\">\"<\/span><span class=\"s\">new_col<\/span><span class=\"sh\">\"<\/span><span class=\"p\">))<\/span>  <span class=\"c1\"># \u5217\u306e\u8ffd\u52a0\r\n<\/span>    <span class=\"p\">.<\/span><span class=\"nf\">filter<\/span><span class=\"p\">(<\/span><span class=\"n\">pl<\/span><span class=\"p\">.<\/span><span class=\"nf\">col<\/span><span class=\"p\">(<\/span><span class=\"sh\">\"<\/span><span class=\"s\">sepal_length<\/span><span class=\"sh\">\"<\/span><span class=\"p\">)<\/span> <span class=\"o\">&gt;<\/span> <span class=\"mi\">5<\/span><span class=\"p\">)<\/span>                          <span class=\"c1\"># \u884c\u306e\u9078\u629e\r\n<\/span>    <span class=\"p\">.<\/span><span class=\"nf\">group_by<\/span><span class=\"p\">(<\/span><span class=\"sh\">\"<\/span><span class=\"s\">species<\/span><span class=\"sh\">\"<\/span><span class=\"p\">)<\/span>                                         <span class=\"c1\"># \u30b0\u30eb\u30fc\u30d7\u5316\r\n<\/span>    <span class=\"p\">.<\/span><span class=\"nf\">agg<\/span><span class=\"p\">(<\/span><span class=\"n\">pl<\/span><span class=\"p\">.<\/span><span class=\"nf\">all<\/span><span class=\"p\">().<\/span><span class=\"nf\">mean<\/span><span class=\"p\">())<\/span>                                        <span class=\"c1\"># \u5168\u5217\u306b\u5bfe\u3057\u3066\u5e73\u5747\u3092\u96c6\u8a08\r\n<\/span>)\r\ndf_agg.write_excel(\"result.xlsx\")                                #\u7d50\u679c\u3092\u30a8\u30af\u30bb\u30eb\u3078\r\n\r\n<\/code><\/pre>\n<p data-sourcepos=\"76:1-76:269\">Polars\u306f\u4e0a\u306e\u30b3\u30fc\u30c9\u306e\u3088\u3046\u306b\u3001\u51e6\u7406\u3092\u300c.\u300d\u306e\u30e1\u30bd\u30c3\u30c9\u30c1\u30a7\u30fc\u30f3\u3092\u7e4b\u3044\u3067\u8a18\u8ff0\u3059\u308b\u3053\u3068\u304c\u591a\u3044\u3067\u3059\u3002<br \/>\n\u57fa\u672c\u7684\u306b\u306f\u66f8\u3044\u305f\u9806\u306b\u51e6\u7406\u304c\u8d70\u308b\u306e\u3067\u3001\u4f55\u3082\u8003\u3048\u305a\u306b\u3064\u306a\u3052\u3066\u3044\u3051\u3070OK\u3067\u3059\u3002<br \/>\n\uff08\u3000\uff09\u5185\u3067\u306f\u3001\u30ab\u30c3\u30b3\u304c\u9589\u3058\u308b\u307e\u3067\u3000\u6539\u884c\u3082\u4f7f\u3048\u30b5\u30f3\u30d7\u30eb\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u3088\u3046\u306b\u3001\u898b\u3084\u3059\u304f\u3067\u304d\u307e\u3059\u3002<\/p>\n<p data-sourcepos=\"78:1-78:33\">\u4e0a\u8a18\u3067\u3001df = pl.\u3000\u306f porlars.DataFrame\u3000\u306e\u5ba3\u8a00\u3067\u3059<\/p>\n<ul data-sourcepos=\"80:1-86:0\">\n<li data-sourcepos=\"80:1-80:39\"><code>read_csv<\/code>\uff1a\u30c7\u30fc\u30bf\u306e\u8aad\u307f\u8fbc\u307f\uff08\u203bcsv\u3084xlsx\u3084DB\u3082\u8aad\u307f\u8fbc\u3081\u307e\u3059\uff09<\/li>\n<li data-sourcepos=\"81:1-81:25\"><code>select<\/code>\uff1a\u5217\u306e\u9078\u629e<\/li>\n<li data-sourcepos=\"82:1-82:31\"><code>with_columns<\/code>\uff1a\u5217\u306e\u8ffd\u52a0<\/li>\n<li data-sourcepos=\"83:1-83:25\"><code>filter<\/code>\uff1a\u884c\u306e\u9078\u629e<br \/>\n\u6761\u4ef6\u6307\u5b9a\u3000\u5927\u3000\u3000\u3000&gt;\u00a0 \u00a0 &gt;=\u00a0 \u00a0 ==\u00a0 \u00a0=&lt;\u00a0 \u00a0 &lt;\u00a0 \u00a0 \u5c0f<br \/>\n\u3000\u3000\u3000\u3000\u3000\u4e0d\u4e00\u81f4\u00a0 \u3000\u3000\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 !=\u3000<br \/>\n\u3000\u3000\u3000\u3000\u3000\u4e00\u81f4\u3000\u3000\u3000\u3000.is_in([&#8220;a&#8221;,&#8221;b&#8221;,&#8221;c&#8221;])\u3000\u5217\u5185\u306e\u884c\u306e\u5024\u5217\u6319<\/li>\n<li data-sourcepos=\"84:1-84:29\"><code>group_by<\/code>\uff1a\u30b0\u30eb\u30fc\u30d7\u5316<\/li>\n<li data-sourcepos=\"85:1-86:0\"><code>agg<\/code>\uff1a\u8a08\u7b97\u3000\uff08\u5408\u8a08\u30fb\u5e73\u5747\u30fb\u5206\u6563\u30fb\u6a19\u6e96\u504f\u5dee\u306a\u3069\u304c\u3067\u304d\u307e\u3059\uff09<\/li>\n<li data-sourcepos=\"85:1-86:0\">write_excel: \u7d50\u679c\u3092\u30a8\u30af\u30bb\u30eb\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u51fa\u3059<\/li>\n<\/ul>\n<p data-sourcepos=\"87:1-87:158\">\u4ee5\u4e0a\u3000\u90e8\u5206\u5f15\u7528\u7d42\u308f\u308a<\/p>\n<h4 data-sourcepos=\"87:1-87:158\">polars\u3067\u8907\u6570\u30a8\u30af\u30bb\u30eb\u3092\u30ea\u30f3\u30af\u3067\u304d\u308b<\/h4>\n<p>\u3055\u3089\u306b\u91cd\u8981\u306a\u3053\u3068\u3001polars\u306f\u3001\u8907\u6570\u30d5\u30a1\u30a4\u30eb\u3092\u30ad\u30fc\u9805\u76ee\u4e00\u81f4\u3067\u3064\u306a\u3052\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3002DB\u8a00\u8a9e\u3067\u306f\u666e\u901a\u306eSQL\u304cpolars\u3067\u3067\u304d\u308b\u3002<br \/>\n<span style=\"color: #0000ff;\"><strong>\u30a8\u30af\u30bb\u30eb\u3067\u306f\u82e6\u624b\u306a\u3001\u8907\u6570\u30d5\u30a1\u30a4\u30eb\u30ea\u30f3\u30af\u304cpolars\u3092\u5229\u7528\u3059\u308b\u3068\u7c21\u5358\u3060\u3002<\/strong><\/span><\/p>\n<p>\u5171\u901a\u306ekey\u9805\u76ee\u304c\u3042\u308b\u30a8\u30af\u30bb\u30ebA\u3068\u30a8\u30af\u30bb\u30ebB\u3092polars\u306eread_excel\u3067\u8aad\u307f\u8fbc\u307f\u3001\u30ea\u30f3\u30af\u3057\u305f\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u4f5c\u308a\u3001\u30a8\u30af\u30bb\u30eb\u30d5\u30a1\u30a4\u30ebC\u306b\u66f8\u304d\u51fa\u3059\u65b9\u6cd5\uff01<\/p>\n<p>df_a=pl.read_excel(&#8220;path A&#8221;)<br \/>\ndf_b=pl.read_excel(&#8220;path B&#8221;)<br \/>\ndf_join=df_a.join(df_b, on=&#8221;key&#8221;)<br \/>\ndf_join.write_excel(&#8220;path C&#8221;)<\/p>\n<hr \/>\n<h3 data-sourcepos=\"87:1-87:158\">\uff08\u88dc\u8db3\uff09<\/h3>\n<p data-sourcepos=\"87:1-87:158\">\u4e0a\u8a18\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u3001\u30cd\u30c3\u30c8\u306b\u3042\u308b5\u5217x150\u884c\u30c7\u30fc\u30bf\u3092\u8aad\u307f\u8fbc\u307f\u3001\u5217\u9078\u629e\u3068\u8ffd\u52a0\u30fb\u6761\u4ef6\u4ed8\u3051\u3067\u884c\u306e\u62bd\u51fa\u30fb\u30b0\u30eb\u30fc\u30d7\u5316\u30fb\u96c6\u8a08\uff08\u5e73\u5747\u5024\uff09\u3092\u884c\u3063\u3066\u3044\u307e\u3059\u3002<br \/>\n\u5404\u5217\u306e\u5217\u540d\u3000columns\u3000\u306e\u30ea\u30b9\u30c8\u306f<br \/>\nprint(df.columns)\u3000<br \/>\n\u3067\u5f97\u3089\u308c\u307e\u3059\u3002<br \/>\n[&#8216;sepal_length&#8217;, &#8216;sepal_width&#8217;, &#8216;petal_length&#8217;, &#8216;petal_width&#8217;, &#8216;species&#8217;]\n<p data-sourcepos=\"87:1-87:158\">\u3053\u308c\u3092\u3082\u3068\u306b\u3001\u5217\u3092\u6271\u3046\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u3063\u3066\u3044\u304f\u3053\u3068\u306b\u306a\u308a\u307e\u3059\u3002\u3053\u306e\u30b3\u30f3\u30de\u304c\u30bb\u30d1\u30ec\u30fc\u30bf\u306e150\u884c\u30c7\u30fc\u30bf\uff43\uff53\uff56\u306f\u3053\u3093\u306a\u5f62\u3067\u3059\u3002<\/p>\n<div>\n<table style=\"width: 100%; height: 168px;\" width=\"462\">\n<tbody>\n<tr style=\"height: 21px;\">\n<td style=\"height: 21px; text-align: center;\" width=\"102\">sepal_length<\/td>\n<td style=\"height: 21px; text-align: center;\" width=\"98\">sepal_width<\/td>\n<td style=\"height: 21px; text-align: center;\" width=\"99\">petal_length<\/td>\n<td style=\"height: 21px; text-align: center;\" width=\"94\">petal_width<\/td>\n<td style=\"height: 21px; text-align: center;\" width=\"69\">species<\/td>\n<\/tr>\n<tr style=\"height: 21px;\">\n<td style=\"height: 21px; text-align: center;\">5.1<\/td>\n<td style=\"height: 21px; text-align: center;\">3.5<\/td>\n<td style=\"height: 21px; text-align: center;\">1.4<\/td>\n<td style=\"height: 21px; text-align: center;\">0.2<\/td>\n<td style=\"height: 21px; text-align: center;\">setosa<\/td>\n<\/tr>\n<tr style=\"height: 21px;\">\n<td style=\"height: 21px; text-align: center;\">4.9<\/td>\n<td style=\"height: 21px; text-align: center;\">3<\/td>\n<td style=\"height: 21px; text-align: center;\">1.4<\/td>\n<td style=\"height: 21px; text-align: center;\">0.2<\/td>\n<td style=\"height: 21px; text-align: center;\">setosa<\/td>\n<\/tr>\n<tr style=\"height: 21px;\">\n<td style=\"height: 21px; text-align: center;\">4.7<\/td>\n<td style=\"height: 21px; text-align: center;\">3.2<\/td>\n<td style=\"height: 21px; text-align: center;\">1.3<\/td>\n<td style=\"height: 21px; text-align: center;\">0.2<\/td>\n<td style=\"height: 21px; text-align: center;\">setosa<\/td>\n<\/tr>\n<tr style=\"height: 21px;\">\n<td style=\"height: 21px; text-align: center;\">\u00a0<\/td>\n<td style=\"height: 21px; text-align: center;\">\u00a0<\/td>\n<td style=\"height: 21px; text-align: center;\">\u00a0<\/td>\n<td style=\"height: 21px; text-align: center;\">\u00a0<\/td>\n<td style=\"height: 21px; text-align: center;\">\u00a0<\/td>\n<\/tr>\n<tr style=\"height: 21px;\">\n<td style=\"height: 21px; text-align: center;\">6.5<\/td>\n<td style=\"height: 21px; text-align: center;\">3<\/td>\n<td style=\"height: 21px; text-align: center;\">5.2<\/td>\n<td style=\"height: 21px; text-align: center;\">2<\/td>\n<td style=\"height: 21px; text-align: center;\">virginica<\/td>\n<\/tr>\n<tr style=\"height: 21px;\">\n<td style=\"height: 21px; text-align: center;\">6.2<\/td>\n<td style=\"height: 21px; text-align: center;\">3.4<\/td>\n<td style=\"height: 21px; text-align: center;\">5.4<\/td>\n<td style=\"height: 21px; text-align: center;\">2.3<\/td>\n<td style=\"height: 21px; text-align: center;\">virginica<\/td>\n<\/tr>\n<tr style=\"height: 21px;\">\n<td style=\"height: 21px; text-align: center;\">5.9<\/td>\n<td style=\"height: 21px; text-align: center;\">3<\/td>\n<td style=\"height: 21px; text-align: center;\">5.1<\/td>\n<td style=\"height: 21px; text-align: center;\">1.8<\/td>\n<td style=\"height: 21px; text-align: center;\">virginica<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p data-sourcepos=\"87:1-87:158\">\u3053\u308c\u3092\u8aad\u307f\u8fbc\u3080\u3068\u3001\u5217\u540d\u30fb\u5217\u306e\u30c7\u30fc\u30bf\u7a2e\u5225\uff08\u6587\u5b57\u30fb\u6570\u5b57\u306a\u3069\uff09\u304c\u4e0b\u8a18\u306e\u3088\u3046\u306b\u81ea\u52d5\u5224\u5225\u3055\u308c\u307e\u3059\u3002<\/p>\n<p data-sourcepos=\"87:1-87:158\">\uff11\uff0ePandas\u3067\u81ea\u52d5\u3067\u4ed8\u304f\u884c\u30ca\u30f3\u30d0\u30fc\u304c\u306a\u3044\u3002\u3053\u308c\u5358\u4f53\u3067\u3001\u8907\u6570\u306e\u30c7\u30fc\u30bf\u30d5\u30ec\u30fc\u30e0\u3092\u30ad\u30fc\u9805\u76ee\u3067\u30ea\u30f3\u30af\u3067\u304dSQL\u3082\u4f7f\u3048\u3001CSV\u3084XLSX\u3084\u5404\u7a2e\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u304b\u3089\u76f4\u63a5\u8aad\u307f\u8fbc\u3081\u308b\u3002<br \/>\n\uff12\uff0e\u6587\u5b57\u53d6\u308a\u6271\u3044\u3067\u6a19\u6e96\u3067\u6b63\u898f\u8868\u73fe\u304c\u4f7f\u3048\u308b\u3002\uff08\u4e0a\u8a18\u306e\u5217\u9078\u629e\u3067\u3000<code><span class=\"s\">\"sepal_\"\u3000<\/span><\/code>\u3067\u59cb\u307e\u308b\u3082\u306e\u3092\u9078\u629e\u3082\u5229\u7528\uff09<br \/>\n\uff13\uff0e\u4e0a\u8a18\u30d7\u30ed\u30b0\u30e9\u30e0\u306e\u7d50\u679c\u306f\u4e0b\u8a18<\/p>\n<p>print(df_agg)\u3000<\/p>\n<p style=\"text-align: left;\" data-sourcepos=\"87:1-87:158\">shape: (3, 4)<br \/>\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<br \/>\n\u2502 species \u2506 sepal_length \u2506 sepal_width \u2506 new_col \u2502<br \/>\n\u2502 &#8212; &#8212; &#8211;\u2506 &#8212; &#8212;&#8212;&#8212; \u2506 &#8212;&#8212;&#8212;&#8212;&#8211; \u2506 &#8212;&#8212;&#8211; \u2502<br \/>\n\u2502\u00a0 \u00a0 \u00a0str\u00a0 \u00a0 \u00a0\u2506\u00a0 \u00a0 \u00a0 f64\u00a0 \u00a0 \u00a0\u2506\u00a0 \u00a0 \u00a0 f64\u00a0 \u00a0\u2506\u00a0 \u00a0 \u00a0 \u00a0 f64\u00a0 \u00a0 \u00a0\u2502<br \/>\n\u255e\u2550\u2550\u2550\u2550\u2550\u256a\u2550\u2550\u2550\u2550\u2550\u256a\u2550\u2550\u2550\u2550\u2550\u256a\u2550\u2550\u2550\u2550\u2550\u2550\u2561<br \/>\n\u2502 virginica \u2506 6.622449 \u2506 2.983673 \u2506 5.967347 \u2502<br \/>\n\u2502 versicolor \u2506 5.997872 \u2506 2.804255 \u2506 5.608511 \u2502<br \/>\n\u2502 setosa\u00a0 \u00a0\u2506 5.313636 \u2506 3.713636 \u2506 7.427273 \u2502<br \/>\n\u250c\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u252c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510<\/p>\n<p style=\"text-align: left;\" data-sourcepos=\"87:1-87:158\"><strong>\u8a08\u7b97\u6642\u9593<\/strong><br \/>\n\u4e0a\u8a18\u30d7\u30ed\u30b0\u30e9\u30e0\u306f\u3001\u30cd\u30c3\u30c8\u63b2\u8f09\u30c7\u30fc\u30bf\uff085\u5217\uff58150\u884c\uff09\u3092\u8aad\u307f\u8fbc\u3093\u3067\u3044\u308b\u306e\u3067\u3001\u901a\u4fe1\u74b0\u5883\u306e\u5f71\u97ff\u3092\u53d7\u3051\u30010.5\u79d2\u7a0b\u5ea6\u304b\u304b\u308a\u307e\u3057\u305f\u304c<br \/>\n\u30ce\u30fc\u30c8\u30d1\u30bd\u30b3\u30f3\u306b\u53d6\u308a\u8fbc\u3093\u3060\uff43\uff53\uff56\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u306e\u8aad\u307f\u8fbc\u307f\u3067\u306f\u3001\u6240\u8981\u6642\u9593\u306f0.03\u79d2\u3000\u3067\u3057\u305f\u3002<\/p>\n<p data-sourcepos=\"87:1-87:158\"><span style=\"font-size: 16px;\"><strong>\u53c2\u8003\u306b\u306a\u308b\u89e3\u8aac\u30b5\u30a4\u30c8<br \/>\n<\/strong>\u3000\u4e09\u91cd\u5927\u5b66\u5965\u6751\u6674\u5f66\u540d\u8a89\u6559\u6388\u3000\u5c0e\u5165\u304b\u3089\u5229\u7528\u4f8b\u307e\u3067\u30ef\u30f3\u30bb\u30c3\u30c8[2023-10-13]\u7248<strong><br \/>\n<\/strong>\u3000\u203b\u5143\u60c5\u5831\u51e6\u7406\u5b66\u4f1a\u30c7\u30fc\u30bf\u30b5\u30a4\u30a8\u30f3\u30b9\u6559\u80b2\u59d4\u54e1\u4f1a\u59d4\u54e1<br \/>\n<\/span>\u3000\u00a0<span style=\"font-size: 14px;\"><strong>Polars<\/strong><\/span>\u3000<a href=\"https:\/\/okumuralab.org\/~okumura\/python\/polars.html\">\u00a0https:\/\/okumuralab.org\/~okumura\/python\/polars.html<\/a><\/p>\n<p>&nbsp;<\/p>\n<h4 data-sourcepos=\"87:1-87:158\">\u3088\u304f\u5229\u7528\u3059\u308b\u6a5f\u80fd\u306e\u88dc\u8db3\u8aac\u660e<\/h4>\n<\/section>\n<p>\u3000\u5927\u91cf\u30c7\u30fc\u30bf\u304b\u3089\u3001\u7279\u5b9a\u306e\u30e6\u30cb\u30fc\u30af\u306a\u9805\u76ee\u30ea\u30b9\u30c8\u3068\u305d\u306e\u95a2\u4fc2\u6570\u91cf\u306e\u5408\u8a08\u3092\u6c42\u3081\u308b\u5834\u5408\u3001<br \/>\n<span style=\"color: #0000ff;\"><strong>\u30a4\u30e1\u30fc\u30b8\u4f8b<\/strong><\/span>\u3000<span style=\"color: #0000ff;\"><strong>\u770c\u540d\u30fb\u5e97\u540d\u3054\u3068\u306e\u58f2\u4e0a\u5408\u8a08<\/strong><\/span>\u3092\u6c42\u3081\u305f\u3044<br \/>\n\u6b21\u306e\u624b\u9806\u3092\u591a\u7528\u3002<\/p>\n<p><strong>group_by([group\u9805\u76ee\u30ea\u30b9\u30c8]).agg(pl.col([\u5408\u8a08\u9805\u76ee\u30ea\u30b9\u30c8]).sum())\u3000<\/strong><\/p>\n<p><span style=\"font-size: 14.08px;\">\uff11\uff0egroup_by\u306e\u9805\u76ee\u30ea\u30b9\u30c8\u8a18\u8f09\u9805\u76ee\uff08\u770c\u540d\u30fb\u5e97\u540d\uff09\u306e\u884c\u304c\u9078\u629e\u3055\u308c\u3001<br \/>\n<\/span><span style=\"font-size: 14.08px;\">\uff12\uff0e\u6b21\u306eagg\uff08\uff1d\u8a08\u7b97\uff09\u3067\u6307\u5b9a\u3055\u308c\u305f\u9805\u76ee\uff08\u5e97\u306e\u58f2\u4e0a\uff09\u304c\u96c6\u3081\u3089\u308c\u3066\u9805\u76ee\u5185\u306e\u30ea\u30b9\u30c8\uff08list\uff09\u306b\u306a\u308a\u3001<br \/>\n<\/span><span style=\"font-size: 14.08px;\">\uff13\uff0esum()\u3067\u305d\u306e\u30b7\u30ea\u30fc\u30ba\u306e\u5408\u8a08\u8a08\u7b97\u3055\u308c\u3001\u7d50\u679c\u306f<br \/>\n<\/span><span style=\"font-size: 14.08px;\">\uff14\uff0egroup\u9805\u76ee\u30ea\u30b9\u30c8\u3068\u5408\u8a08\u9805\u76ee\u30ea\u30b9\u30c8\u306eDataFrame\u3000\uff08<span style=\"color: #0000ff;\"><strong>\u770c\u540d\u30fb\u5e97\u540d\u30fb\u58f2\u4e0a<\/strong><\/span>\uff09\u306b\u306a\u308b<\/span><\/p>\n<section class=\"it-MdContent darkMode\">\n<p>\u203bpl\u3067\u306f\u3001\u30c9\u30c3\u30c8\u3064\u306a\u304e\u3067\u3001\u5de6\u304b\u3089\u9806\u306b\u5b9f\u884c\u3055\u308c\u3001\u6b21\u306e\u30c9\u30c3\u30c8\u306b\u6e21\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>agg: aggregation\u3000\u8a08\u7b97\u3059\u308b<br \/>\nsum: \u5408\u8a08\u3059\u308b<br \/>\ngroup:\u3000\u30b0\u30eb\u30fc\u30d7<br \/>\nlist:\u3000\u30c7\u30fc\u30bf\u306e\u5217<\/p>\n<p>\u30e1\u30e2\u30ea\u30fc\u4e0d\u8db3\u30a8\u30e9\u30fc\uff1a\u3000polars\u306fcsv\u306a\u3069\u3092\u8aad\u307f\u8fbc\u3080\u5834\u5408\u3001\u5217\u306e\u5b9a\u7fa9\u306e\u305f\u3081\u306e\u8aad\u307f\u8fbc\u307f\u884c\u6570\u5236\u9650\uff08\u30c7\u30d5\u30a9\u30eb\u30c8100)\u304c\u539f\u56e0\u3067,\u3000\u5b9a\u7fa9\u56f0\u96e3\u30fb\u30e1\u30e2\u30ea\u30fc\u4e0d\u8db3\u306a\u3069\u306e\u30a8\u30e9\u30fc\u767a\u751f\u3059\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002\u305d\u306e\u5834\u5408\u306f\u3001read_option\u3092\u8abf\u6574\u3059\u308b\u3068\u89e3\u6d88\u3067\u304d\u308b\u5834\u5408\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\uff08\u4f8b\uff1a\u3000pl.read_csv(file=&#8221;file_name.csv&#8221;, read_option{<span style=\"color: #0000ff;\"><strong>infer_schema_length: None<\/strong><\/span>})\u306b\u3059\u308b\u3068\u3001\u5168\u884c\u3092\u8aad\u307f\u8fbc\u307f\u307e\u3059\u3002<\/p>\n<\/section>\n","protected":false},"excerpt":{"rendered":"Python\u306f\u3001\u8a18\u8ff0\u304c\u89e3\u308a\u3084\u3059\u304f\u30b3\u30f3\u30d1\u30a4\u30eb\u4e0d\u8981\u3067\u4f7f\u3048\u308b\u3053\u3068\u304c\u8a55\u4fa1\u3055\u308c\u3001\u5927\u898f\u6a21\u958b\u767a\u306b\u3082\u5229\u7528\u3055\u308c\u3066\u3044\u307e\u3059\u3002 \u4e00\u65b9\u3001\u5b9f\u52d9\u3067\u4f7f\u3046\u3053\u3068\u304c\u591a\u3044\u30a8\u30af\u30bb\u30eb\u3084\u8868\u5f62\u5f0f\u30c7\u30fc\u30bf\u3092\u53d6\u308a\u6271\u3046\u306b\u306f\u3001Python\u306e\u62e1\u5f35\u30e2\u30b8\u30e5\u30fc\u30eb\u306eNumpy\u3068\u304bPand &#8230;","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"vk-ltc-link":"","vk-ltc-target":"0","footnotes":""},"categories":[24],"tags":[],"class_list":["post-4300","post","type-post","status-publish","format-standard","hentry","category-iot-it"],"_links":{"self":[{"href":"https:\/\/jfs.or.jp\/jfs-cs\/wp-json\/wp\/v2\/posts\/4300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jfs.or.jp\/jfs-cs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jfs.or.jp\/jfs-cs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jfs.or.jp\/jfs-cs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/jfs.or.jp\/jfs-cs\/wp-json\/wp\/v2\/comments?post=4300"}],"version-history":[{"count":45,"href":"https:\/\/jfs.or.jp\/jfs-cs\/wp-json\/wp\/v2\/posts\/4300\/revisions"}],"predecessor-version":[{"id":4657,"href":"https:\/\/jfs.or.jp\/jfs-cs\/wp-json\/wp\/v2\/posts\/4300\/revisions\/4657"}],"wp:attachment":[{"href":"https:\/\/jfs.or.jp\/jfs-cs\/wp-json\/wp\/v2\/media?parent=4300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jfs.or.jp\/jfs-cs\/wp-json\/wp\/v2\/categories?post=4300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jfs.or.jp\/jfs-cs\/wp-json\/wp\/v2\/tags?post=4300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}