Skip to Content
エクセルのためのPython (Japanese Edition), 2nd Edition
book

エクセルのためのPython (Japanese Edition), 2nd Edition

by Felix Zumstein
May 2026
Intermediate
418 pages
6h 42m
Japanese
O'Reilly Media, Inc.
Content preview from エクセルのためのPython (Japanese Edition), 2nd Edition

第15章. ReaderおよびWriterパッケージによるExcel ファイルの操作

この作品はAIを使って翻訳されている。ご意見、ご感想をお待ちしている:translation-feedback@oreilly.com

この章では、reader および writer パッケージについて紹介する。これらは、Excel をインストールしなくても、Excel ファイルを直接読み書きできる。read_excelやto_excel関数を呼び出す際、pandas は内部でこれらを使用している。reader および writer パッケージを直接使用することで、より複雑な Excel レポートを作成できる。 また、pandasのその他の機能は必要なく、Excelファイルの読み書きのみを行うプロジェクトに取り組む場合、pandasのフルスタックをインストールするのは過剰な措置となるだろう。 この章では、各パッケージの概要を説明した後、その仕組みについて学ぶ。その後、DataFrameをExcelに書き出す際のスタイル付けについて検討する。最後に、レポート作成のケーススタディをもう一度取り上げる。前章と同様、この章でもExcelのインストールは不要であり、すべてのコードサンプルはWindows、macOS、Linuxで実行可能だ。

Excelファイルの読み書き

には、Excel ワークブックを読み書きできる Python パッケージが多数存在する。このセクションでは、本章で取り上げるパッケージの概要を説明する。ただし、混乱を避けるために、Excel ワークブックの読み取り、書き込み、編集のいずれを行いたいかによって、簡単な推奨事項から始めよう:

読み取り

、python-calamine、またはfastexcelのいずれかを使用する。これらのパッケージはいずれも、Rustで実装されたライブラリであるcalamineを基盤としている。pandasやPolars(「最新の代替手段」を参照)engine="calamine"設定して使用するのが最適だが、DataFrameが必要ない場合は、python-calamineを単独で使用することもできる(fastexcelはバージョン1.0のリリースでスタンドアロンモードの提供を予定している)。Polarsはデフォルトでcalamineエンジンを使用するが、pandasでは本書を通じて行ってきたように、明示的にセットする必要がある:

pd.read_excel("filename.xlsx", engine="calamine")

pandasはcalamineエンジンとしてPython-calamineを使用するが、Polarsはfastexcelを使用する。次のセクションで両方のパッケージを紹介する。

執筆

制限にぶつからない限り、XlsxWriter()を使用する。制限にぶつかった場合は、OpenPyXLやExcelizeで問題が解決するかどうか確認する。XlsxWriterを推奨する理由は以下の通りだ:

  • これが最速のライターだ。XlsxWriterはPythonで書かれているが、現在では同じ作者によるRustベースのXlsxWriterプロジェクトも存在する。将来的には、現在の純粋なPython実装よりも数倍高速なPythonパッケージによってラップされることになるだろう。

  • 文書化が非常に充実している。

  • 活発にメンテナンスされている。

  • 完全に互換性のあるExcelワークブックを作成する。

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

大規模言語モデル:難しい部分 (Japanese Edition)

大規模言語モデル:難しい部分 (Japanese Edition)

Thársis T. P. Souza, Jonathan K. Regenstein

Publisher Resources

ISBN: 0642572395971