Skip to Content
ファストAPI
book

ファストAPI

by Bill Lubanovic
March 2025
Intermediate to advanced
280 pages
3h 20m
Japanese
O'Reilly Media, Inc.
Content preview from ファストAPI

第17章. データの発見と可視化

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

プレビュー

この章では、世界中の架空の生き物の小さなデータベースを使用して、データから表、プロット、グラフ、マップを生成する方法を紹介します。

Pythonとデータ

Pythonはここ数年、多くの理由から非常に人気がある:

  • 学習のしやすさ

  • きれいな構文

  • 豊富な標準ライブラリ

  • 膨大な数の高品質サードパーティ製パッケージ

  • データ操作、変換、イントロスペクションを特殊化する

最後の点は、データベース作成のための従来のETLタスクに常に関連している。PyDataと呼ばれる非営利のグループは、Pythonを使ったオープンソースのデータ分析のためのカンファレンスの開催やツールの開発まで行っている。 Pythonの人気は、最近のAIの急増や、AIモデルに供給するデータを準備するためのツールの必要性も反映している。

この章では、いくつかのPythonデータパッケージを試して、それらが最新のPythonウェブ開発とFastAPIにどのように関係しているかを見ていく。

PSVテキスト出力

このセクションでは、付録Bにリストされているクリーチャーを使用する。データは本書のGitHubリポジトリにあるパイプ区切りのファイルcryptid.psvとSQLiteデータベースcryptid.dbにある。tsv)ファイルが一般的だが、カンマはデータ・セル自体で使用され、タブは他の空白と区別しにくいことがある。パイプ文字( )は区別しやすく、標準的なテキストでは十分に珍しいため、良い区切り文字として機能する。|

まず.psvテキストファイルを試してみよう。簡単のためにテキスト出力の例だけを使い、次にSQLiteデータベースを使った完全なウェブの例を見てみよう。

.psvファイルの初期ヘッダ行には、フィールドの名前が書かれている:

  • name

  • country ( は多くの国を意味する)*

  • area (任意、米国の州またはその他の国の地域)

  • description

  • aka (とも呼ばれる)

ファイル内の残りの行は、| の文字で区切られたフィールドの順番で、一度に一匹のクリーチャーを描写する。

シーエスブイ

DictReader例17-1では、 の生物データをPythonのデータ構造に 。 まず、パイプで区切られたファイルcryptids.psvを標準のPython csvパッケージで読み込むと、タプルのリストが得られる(各タプルはファイルのデータ行を表す)。

例には型ヒントを入れているが、旧バージョンのPythonを使用している場合はヒントを取り除いてもコードは動作する。 少し木を節約するために、ヘッダと最初の5行だけを出力してみよう。1

例 17-1. PSVファイルをcsvで読み取る(load_csv.py)
import csv
import sys

def read_csv(fname: str) -> list[tuple]:
    with open(fname) as file:
        data = [row for row in csv.reader(file, delimiter="|")]
    return data

if __name__ == "__main__":
    data = read_csv(sys.argv[1])
    for row in 
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

GitHubアクションを学ぶ

GitHubアクションを学ぶ

Brent Laster
仕事ではじめる機械学習 第2版

仕事ではじめる機械学習 第2版

有賀 康顕, 中山 心太, 西林 孝

Publisher Resources

ISBN: 9798341624658