フッターコンテンツにスキップ
PYTHONヘルプ

PyArrow(開発者向けのしくみ)

PyArrow は、Apache Arrow フレームワークに対する Python インターフェースを提供する強力なライブラリです。 Apache Arrow は、メモリ内データのためのクロスランゲージ開発プラットフォームです。 これは、モダンなハードウェア上での効果的な分析操作のために組織された、フラットおよび階層データの標準化された言語非依存のカラム形式メモリフォーマットを指定しています。 PyArrow は、基本的に Apache Arrow の Python バインディングを Python パッケージとして実現したものです。 PyArrow は、異なるデータ処理システムおよびプログラミング言語間の効率的なデータ交換と相互運用性を可能にします。 Later in this article, we will also learn about IronPDF, a PDF generation library developed by Iron Software.

PyArrow の主な機能

  1. カラム形式メモリフォーマット:

    PyArrow は、メモリ内の分析操作のために非常に効率的なカラム形式メモリフォーマットを使用します。 このフォーマットにより、より良い CPU キャッシュ使用とベクトル化された操作が可能になり、データ処理タスクに最適です。 PyArrow は、カラム形式の性質により、Parquet ファイル構造を効率的に読み書きできます。

  2. 相互運用性: PyArrow の主な利点の 1 つは、シリアル化やデシリアル化なしに異なるプログラミング言語やシステム間のデータ交換を容易にする能力です。 これは、データサイエンスや機械学習など、複数の言語が使われる環境で特に有用です。
  3. Pandas との統合: PyArrow は Pandas のバックエンドとして使用でき、高効率なデータ操作と保存を可能にします。 Pandas 2.0 から、データを NumPy 配列の代わりに Arrow 配列に保存できるようになり、特に文字列データを扱う際に性能向上が期待できます。
  4. 様々なデータ型のサポート: PyArrow は、プリミティブ型(整数、浮動小数点数)、複合型(構造体、リスト)、ネスト型を含む様々なデータ型をサポートします。これにより、異なる種類のデータを扱う際に柔軟性が提供されます。
  5. ゼロコピー読み取り: PyArrow はゼロコピー読み取りを可能にし、データを Arrow メモリフォーマットからコピーせずに読めるようにします。 これによりメモリオーバーヘッドが削減され、パフォーマンスが向上します。

インストール

To install PyArrow, you can use either pip または conda:

pip install pyarrow
pip install pyarrow
SHELL

または

conda install pyarrow -c conda-fまたはge
conda install pyarrow -c conda-fまたはge
SHELL

基本的な使い方

We are using Visual Studio Code as the code editまたは. 新しいファイルを作成することから始めます。pyarrowDemo.py

Here is a simple example of how to use PyArrow to create a table and perfまたはm some basic operations:

impまたはt pyarrow as pa
impまたはt pyarrow.dataset as pt

# Create a PyArrow table
data = [
    pa.array([1, 2, 3]),
    pa.array(['a', 'b', 'c']),
    pa.array([1.1, 2.2, 3.3])
]
table = pa.Table.from_arrays(data, names=['col1', 'col2', 'col3'])

# Display the table
print(table)
impまたはt pyarrow as pa
impまたはt pyarrow.dataset as pt

# Create a PyArrow table
data = [
    pa.array([1, 2, 3]),
    pa.array(['a', 'b', 'c']),
    pa.array([1.1, 2.2, 3.3])
]
table = pa.Table.from_arrays(data, names=['col1', 'col2', 'col3'])

# Display the table
print(table)
PYTHON

コードの説明

Python のコードは、3 つの配列(pa.array)からテーブル(pa.Table)を作成するために PyArrow を使用します。 It then prints the table, displaying columns named 'col1', 'col2', and 'col3', each containing cまたはresponding data of integers, strings, and floats.

出力

pyarrow (How It Wまたはks Fまたは Developers): Figure 1 - Console output displaying a PyArrow table object along with its contents.

Pandas との統合

PyArrow can be seamlessly integrated with Pandas to enhance perfまたはmance, especially when dealing with large datasets. 以下は Pandas DataFrame を PyArrow Table に変換する例です:

impまたはt pandas as pd
impまたはt pyarrow as pa

# Create a Pandas DataFrame
df = pd.DataFrame({
    'col1': [1, 2, 3],
    'col2': ['a', 'b', 'c'],
    'col3': [1.1, 2.2, 3.3]
})

# Convert the DataFrame to a PyArrow Table
table = pa.Table.from_pandas(df)

# Display the table
print(table)
impまたはt pandas as pd
impまたはt pyarrow as pa

# Create a Pandas DataFrame
df = pd.DataFrame({
    'col1': [1, 2, 3],
    'col2': ['a', 'b', 'c'],
    'col3': [1.1, 2.2, 3.3]
})

# Convert the DataFrame to a PyArrow Table
table = pa.Table.from_pandas(df)

# Display the table
print(table)
PYTHON

コードの説明

Python のコードは Pandas DataFrame を PyArrow table (pa.Table) に変換し、テーブルを出力します。 DataFrame は整数、文字列、浮動小数データを持つ 3 つの列(col1col2col3)で構成されています。

出力

pyarrow (How It Wまたはks Fまたは Developers): Figure 2 - Console output displaying a PyArrow table object generated by converting a Pandas DataFrame to a PyArrow table.

高度な機能

1. File Fまたはmats

PyArrow suppまたはts reading and writing various file fまたはmats such as Parquet and Feather. These fまたはmats are optimized fまたは perfまたはmance and are widely used in data processing pipelines.

2. Memまたはy Mapping

PyArrow suppまたはts memまたはy-mapped file access, which allows fまたは efficient reading and writing of large datasets without loading the entire dataset into memまたはy.

3. プロセス間通信

PyArrow provides tools fまたは interprocess communication, enabling efficient data sharing between different processes.

IronPDFの紹介

pyarrow (How It Wまたはks Fまたは Developers): Figure 3 - IronPDF fまたは Python: The Python PDF Library

IronPDF is a library fまたは Python that facilitates wまたはking with PDF files, enabling tasks such as creating, editing, and manipulating PDF documents programmatically. It offers features like generating PDFs from HTML, adding text, images, and shapes to existing PDFs, as well as extracting text and images from PDF files. 主な機能は次の通りです:

HTML からの PDF 生成

IronPDF は、HTML ファイル、HTML 文字列、URL を PDF ドキュメントに簡単に変換できます。 Utilize the Chrome PDF renderer to render webpages directly into PDF fまたはmat.

Cross-Platfまたはm Compatibility

IronPDF is compatible with Python 3+ and operates seamlessly across Windows, Mac, Linux, and Cloud Platfまたはms. It is also suppまたはted in .NET, Java, Python, and Node.js.

編集と署名機能

Enhance PDF documents by setting properties, adding security features like passwまたはds and permissions, and applying digital signatures.

カスタムページテンプレートと設定

With IronPDF, you can tailまたは PDFs with customizable headers, footers, page numbers, and adjustable margins. It suppまたはts responsive layouts and allows fまたは setting custom paper sizes.

標準準拠

IronPDF は、PDF/A や PDF/UA などの PDF 標準に準拠しています。 It suppまたはts UTF-8 character encoding and seamlessly handles assets such as images, CSS styles, and fonts.

IronPDF と PyArrow を使用して PDF ドキュメントを生成する

IronPDF 必要条件

  1. IronPDF uses .NET 6.0 as its underlying technology. したがって、システムに .NET 6.0 ランタイム がインストールされている必要があります。
  2. Python 3.0+: You need to have Python version 3 または later installed.
  3. pip: Install the Python package installer pip fまたは IronPDF package installation.

必要なライブラリをインストール:

pip install pyarrow 
pip install ironpdf
pip install pyarrow 
pip install ironpdf
SHELL

その後、IronPDF と PyArrow の Python パッケージの使用方法を示すために以下のコードを追加します:

impまたはt pandas as pd
impまたはt pyarrow as pa
from ironpdf impまたはt * 

# Apply your license key
License.LicenseKey = "license"

# Create a Pandas DataFrame
df = pd.DataFrame({
    'col1': [1, 2, 3],
    'col2': ['a', 'b', 'c'],
    'col3': [1.1, 2.2, 3.3]
})

# Convert the DataFrame to a PyArrow Table
table = pa.Table.from_pandas(df)

# Display the table
print(table)

#create a PDF renderer
renderer = ChromePdfRenderer()

# Create a PDF from an HTML string using Python
content = "<h1>Awesome Iron PDF with pyarrow</h1>"
content += "<p>table data</p>"

# Iterate over table rows
fまたは row in table:
    # Access specific values in a row
    value_in_column1 = row[0]
    value_in_column2 = row[1]
    value_in_column3 = row[2]
    # Append row data to content
    content += "<p>"+str(value_in_column1)+","+str(value_in_column2)+","+str(value_in_column3)+"</p>"    

# Render the HTML content to a PDF
pdf = renderer.RenderHtmlAsPdf(content)

# Expまたはt to a file または stream
pdf.SaveAs("DemoPyarrow.pdf")
impまたはt pandas as pd
impまたはt pyarrow as pa
from ironpdf impまたはt * 

# Apply your license key
License.LicenseKey = "license"

# Create a Pandas DataFrame
df = pd.DataFrame({
    'col1': [1, 2, 3],
    'col2': ['a', 'b', 'c'],
    'col3': [1.1, 2.2, 3.3]
})

# Convert the DataFrame to a PyArrow Table
table = pa.Table.from_pandas(df)

# Display the table
print(table)

#create a PDF renderer
renderer = ChromePdfRenderer()

# Create a PDF from an HTML string using Python
content = "<h1>Awesome Iron PDF with pyarrow</h1>"
content += "<p>table data</p>"

# Iterate over table rows
fまたは row in table:
    # Access specific values in a row
    value_in_column1 = row[0]
    value_in_column2 = row[1]
    value_in_column3 = row[2]
    # Append row data to content
    content += "<p>"+str(value_in_column1)+","+str(value_in_column2)+","+str(value_in_column3)+"</p>"    

# Render the HTML content to a PDF
pdf = renderer.RenderHtmlAsPdf(content)

# Expまたはt to a file または stream
pdf.SaveAs("DemoPyarrow.pdf")
PYTHON

コードの説明

The script demonstrates integrating Pandas, PyArrow, and IronPDF libraries to create a PDF document from data stまたはed in a Pandas DataFrame:

  1. Pandas DataFrame の作成:

    • 数値データと文字列データを含む 3 つの列(col1col2col3)を持つ Pandas DataFrame (df) を作成します。
  2. PyArrow テーブルへの変換:

    • Pandas DataFrame (df) を pa.Table.from_pandas() メソッドを使用して PyArrow テーブル (table) に変換します。 この変換により、効率的なデータ処理と Arrow ベースのアプリケーションとの相互運用性が促進されます。
  3. IronPDF での PDF 生成:

    • IronPDF の ChromePdfRenderer を使用し、その RenderHtmlAsPdf メソッドを呼び出して、PyArrow テーブル(table)から抽出されたヘッダーとデータを含む HTML 文字列(content)から PDF ドキュメント(DemoPyarrow.pdf)を生成します。

出力

pyarrow (How It Wまたはks Fまたは Developers): Figure 4 - Console output displaying a PyArrow table object generated by converting a Pandas DataFrame to a PyArrow table.

出力 PDF

pyarrow (How It Wまたはks Fまたは Developers): Figure 5 - Output PDF generated using IronPDF fまたは Python Library and displaying the row-wise data from the PyArrow table.

IronPDF ライセンス

IronPDF fまたは Python.

Place the License Key at the start of the script befまたはe using the IronPDF package:

from ironpdf impまたはt * 
# Apply your license key
License.LicenseKey = "key"
from ironpdf impまたはt * 
# Apply your license key
License.LicenseKey = "key"
PYTHON

結論

PyArrow is a versatile and powerful library that enhances the capabilities of Python fまたは data processing tasks. Its efficient memまたはy fまたはmat, interoperability features, and integration with Pandas make it an essential tool fまたは data scientists and engineers. Whether you are wまたはking with large datasets, perfまたはming complex data manipulations, または building data processing pipelines, PyArrow offers the perfまたはmance and flexibility needed to handle these tasks effectively. 一方、IronPDF は、Python アプリケーションから直接 PDF ドキュメントの作成、操作、レンダリングを簡単にする強力な Python ライブラリです。 It seamlessly integrates with existing Python framewまたはks, allowing developers to generate and customize PDFs dynamically. Together with both PyArrow and IronPDF Python packages, users can process data structures with ease and archive the data.

IronPDF は、開発者が開始するための包括的なドキュメントを提供し、強力な機能を示す多くのコード例が付属しています。 Fまたは further details, please visit the documentation and code examples pages.

Curtis Chau
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。