Skip to Content
Python Polars ―高速なデータ処理を実現する次世代ライブラリ
book

Python Polars ―高速なデータ処理を実現する次世代ライブラリ

by Jeroen Janssens, Thijs Nieuwdorp, 中田 秀基
December 2025
Intermediate to advanced
468 pages
7h 58m
Japanese
O'Reilly Japan, Inc.
Content preview from Python Polars ―高速なデータ処理を実現する次世代ライブラリ

13章要約と集約

データの要約と集約は、未加工のデータセットから意味のある洞察を得るための重要なステップだ。販売データであれ、顧客情報であれ、センサーデータであれ、グループ化して集約することで、重要な疑問に答えたり、明らかではなかった傾向を特定したりすることができる。

以下のような疑問を持つことがあるだろう。

  • 「店舗あたりの平均売上高はいくらか?」
  • 「各顧客が購入した商品の数はいくつか?」
  • 「商品カテゴリ別の月間総支出額はいくらか?」

まさにこうした種類の疑問に役立つのが集約だ。1つまたは複数の列に基づいてデータをグループ化し、合計、平均値、カウントなどの計算を実行することで、データセットの根本的なパターンをより明確に理解できる。

Polarsでは、df.group_by()メソッドにより、このプロセスをシンプルかつ効率的に行うことができる。このメソッドを用いると、1つまたは複数の列とエクスプレッションでDataFrameをグループ化できる。データのグループ化ができれば、さまざまな集約関数を適用して結果を要約することができる。例えば、各グループの合計、平均値、中央値の計算や、各グループの行数カウントなどだ。

本章では、以下のことを学ぶ。

  • GroupByコンテキストと使用可能なメソッド、それらを使用してデータを分析する方法
  • 時間的な値に基づいてデータをグループする方法。df.group_by_dynamic()df.rolling()Expr.over()を用いる。
  • 性能向上のための最適化

必要なファイルを入手する手順は「2章 Polarsを使い始める」で説明している。ここでは、dataサブディレクトリにファイルがあると仮定する。

13.1 分割、適用、結合

グループ化と集約の中心にあるのは、分割、適用、結合の3つの概念だ。これらは、データのグループに対して操作を実行する強力な戦略だ。それぞれの動作を説明しよう。 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

Python Distilled ―プログラミング言語Pythonのエッセンス

Python Distilled ―プログラミング言語Pythonのエッセンス

David M. Beazley, 鈴木 駿
入門 Python 3 第2版

入門 Python 3 第2版

Bill Lubanovic, 鈴木 駿, 長尾 高弘

Publisher Resources

ISBN: 9784814401437Publisher Website