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 ―高速なデータ処理を実現する次世代ライブラリ

10章列の選択と作成

エクスプレッションの仕組みを理解したところで、次はエクスプレッションの使い方を見ていこう。本章ではDataFrameの列に関係する演算を取り上げる†1。既存の列の選択と新規列の作成に焦点を当てる。これらはデータを扱う際に行う、最も一般的な操作だろう。

まず、「7章 エクスプレッションとは」で紹介したdf.select()を再度説明する。次に、より柔軟な列の選択方法を紹介する。いわゆる列セレクタを使用する方法である。セレクタを用いると、列の名前や、データ型、位置に基づいて列を指定することができる。これらはさまざまな方法で組み合わせることができる。さらに、新しい列を作成したり、列を並べ替えたりする方法を紹介する。最後に、関連する列の演算について簡単に説明する。列の名前変更や削除、2つのDataFrameの列の結合などだ。

本章では、スター・ウォーズの世界に登場する我々が好きな反乱軍(rebels)に関するDataFrameを扱う。

starwars = pl.read_parquet("data/starwars.parquet")
rebels = starwars.drop("films").filter(
    pl.col("name").is_in(["Luke Skywalker", "Leia Organa", "Han Solo"])
)

print(rebels[:, :6])  ❶
print(rebels[:, 6:11])
print(rebels[:, 11:])

❶ ここでは、DataFrameを列ごとにスライスして、本のページに収まるようにしている。折り畳みページを使う方法もあるが、この種の本ではあまり使用しない。

shape: ...
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