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

第5章 pandas を使ったデータ 分析

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

この章では、Pythonのデータ分析ライブラリであるpandas、あるいは私が好んで言うところの「超能力を備えたPythonベースのスプレッドシート」について紹介する。pandasライブラリを使えば、Excelでは特に手間がかかる作業も、より簡単かつ迅速に、そしてエラーを減らして行えるようになる。こうした作業には、外部ソースからのデータセットの取得や、統計処理、時系列分析、インタラクティブなグラフの作成などが含まれる。 ExcelのPower Queryに慣れているなら、pandasは同様の領域をカバーしているが、より柔軟性が高い。pandasの最も重要な「超能力」は、ベクトル化とデータの整合性確保だ。前の章でNumPy配列について見たように、ベクトル化により簡潔な配列ベースのコードが書けるようになる一方、データの 整合性確保により、複数の データセットを扱う際にデータの不一致が生じないよう保証される。

この章では、 によるデータ分析の全行程を網羅する。データのクリーニングと準備から始まり、集計、記述統計、可視化を通じて大規模なデータセットから意味を導き出す方法を解説する。章の最後には、pandasを用いたデータのインポートとエクスポートについても見ていく。まずは導入部から始めよう。pandasの主要なデータ構造であるDataFrameとSeriesの紹介から始めよう!

DataFrameとSeries

DataFrame()とSeriesは、pandasの中核となるデータ構造だ。このセクションでは、DataFrameの主要な構成要素であるインデックス、列、データについて紹介する。DataFrameは2次元のNumPy配列に似ているが、列と行のラベルが付いており、各列は異なるデータ型を保持できる。DataFrameから単一の列または行を抽出すると、1次元のSeriesが得られる。 繰り返しになるが、Seriesはラベル付きの1次元NumPy配列に類似性がある。図5-1のDataFrameの構造を見れば、DataFrameがPythonベースのスプレッドシートになることは容易に想像できるだろう。

Diagram comparing a pandas Series and DataFrame, highlighting their structure with indices, columns, and data orientation along axis 0 and axis 1.
図5-1. pandasのSeriesとDataFrame

スプレッドシートからDataFrameへの移行がいかに簡単かを示すために、図5-2の次のExcel表を考えてみよう。これはオンラインコースの受講生とそのスコアを示している。対応するファイルstudents.xlsxは、付属リポジトリのxlフォルダ内にある。

Excel table showing user IDs, names, birth years, countries, scores, and continents for online course students.
図5-2. students .xlsx

このExcel表をPythonで利用できるようにするには、まずpandasをインポートし、そのread_excel関数を使用する。これによりDataFrameが返される:

In [1]: import pandas as ...
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