polarsの日本向けのplugin library
Project description
polars-japanese: Polars 日本語拡張ライブラリ (Polars Japanese Extension Library)
Polars DataFrame/Expression API に、日本語処理や日本固有の操作に関連する機能を追加する拡張ライブラリです。
(This is an extension library that adds functionalities related to Japanese text processing and Japan-specific operations to the Polars DataFrame/Expression API.)
概要 (Overview)
polars-japanese は、データ分析ライブラリ Polars の強力な機能を活用しつつ、日本語特有のデータ処理(全角/半角変換、漢数字変換、和暦変換、祝日判定など)を容易に行えるように設計されています。 Polars の Expression API を拡張し、.ja アクセサを通じて直感的にこれらの機能を利用できます。
ドキュメント (Documentation)
https://polars-japanese.readthedocs.io/ja/latest/
インストール (Installation)
pip install polars-japanese
使い方 (Usage)
polars-japanese をインポートすると、Polars の Expression API に .ja アクセサが追加されます。
import polars as pl
import polars_japanese
from datetime import date
df = pl.DataFrame({
"kanji_num": ["千二百三十四", "五十六", None],
"wareki_str": ["令和6年1月1日", "平成1年12月31日", "昭和45年12月04日"],
"seireki_date": [date(2024, 4, 18), date(1989, 1, 8), date(1970, 10, 10)],
"text_zen": ["Polars", "データ", "123"],
})
df = df.select(
# 漢数字変換
pl.col("kanji_num").ja.to_number().alias("num_from_kanji"),
# 和暦/西暦変換
pl.col("wareki_str").ja.to_datetime().alias("seireki_from_wareki"),
# 祝日判定
pl.col("seireki_date").ja.is_holiday().alias("is_holiday"),
# 全角/半角変換
pl.col("text_zen").ja.to_half_width().alias("to_half"),
pl.col("text_zen").ja.normalize().alias("normalized"),
)
print(df)
# ┌────────────────┬─────────────────────┬────────────┬─────────┬────────────┐
# │ num_from_kanji ┆ seireki_from_wareki ┆ is_holiday ┆ to_half ┆ normalized │
# │ --- ┆ --- ┆ --- ┆ --- ┆ --- │
# │ i64 ┆ date ┆ bool ┆ str ┆ str │
# ╞════════════════╪═════════════════════╪════════════╪═════════╪════════════╡
# │ 1234 ┆ 2024-01-01 ┆ false ┆ Polars ┆ Polars │
# │ 56 ┆ 1989-12-31 ┆ false ┆ データ ┆ データ │
# │ null ┆ 1970-12-04 ┆ true ┆ 123 ┆ 123 │
# └────────────────┴─────────────────────┴────────────┴─────────┴────────────┘
df.ja.to_csv("output_sjis.csv", encoding="shift_jis")
主な機能 (Features)
- 全角/半角変換・正規化:
to_half_width(): 全角文字を半角文字に変換します (Rust Plugin)。to_full_width(): 半角文字を全角文字に変換します (Rust Plugin)。normalize(): Unicode正規化 (NFKC) を行い、さらに日本語テキストでよく問題になる記号やスペースを統一的に処理します(例: ハイフン類を半角-に、チルダ類を全角~に、スペースを半角スペースに統一)。
- 漢数字変換: 文字列中の漢数字をアラビア数字に変換します (Powered by kanjize)。
to_number(): 漢数字(例: "千二百三十四")を整数(例: 1234)に変換しますto_kanji(): 数値を漢数字に変換します。config引数でKanjizeConfigurationを指定できます。
- 和暦/西暦変換: 和暦文字列と西暦日付/文字列を相互に変換します (Powered by japanera)。
to_wareki(): 西暦日付/文字列を和暦文字列(例: "令和6年10月10日")に変換します。format引数で出力フォーマットを指定できます。raise_error引数でエラー発生時の挙動を制御できます。to_datetime(): 和暦文字列を西暦日付に変換します。format引数で入力フォーマットを指定できます。raise_error引数でエラー発生時の挙動を制御できます。
- 祝日判定: 指定された日付が日本の祝日かどうかを判定します (Powered by jpholiday)。
is_holiday(): 日付が祝日であればTrueを返しますis_business_day(): 日付が営業日であればTrueを返します
- CSVエンコーディング指定出力: DataFrameを指定したエンコーディングでCSVファイルに出力します。
DataFrame.ja.to_csv(path, encoding="shift_jis", **kwargs): DataFrameをCSVファイルに書き込みます。
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file polars_japanese-0.1.2.tar.gz.
File metadata
- Download URL: polars_japanese-0.1.2.tar.gz
- Upload date:
- Size: 97.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59e3f4e966a75ec18e5838497a207c17f99f2fcbbe60fe9028d59522516c6e9e
|
|
| MD5 |
0c14d4b864fc3294e7c4e6b85383183e
|
|
| BLAKE2b-256 |
9671d7e0ae710ba8308336044bedc69f475c6746a6ecf594901ccb20a9219120
|
File details
Details for the file polars_japanese-0.1.2-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: polars_japanese-0.1.2-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 3.7 MB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16ca5b0facae5daeb9395ef634784b79f8fbf5c3dd530057ee0b77b4ffef8508
|
|
| MD5 |
a31a5c61aa6a03029529b82a79243c1f
|
|
| BLAKE2b-256 |
650fe736d628704689146dee8614392ab1d0caac4c99e5006eed4992519d2a3c
|
File details
Details for the file polars_japanese-0.1.2-cp38-abi3-manylinux_2_34_x86_64.whl.
File metadata
- Download URL: polars_japanese-0.1.2-cp38-abi3-manylinux_2_34_x86_64.whl
- Upload date:
- Size: 3.5 MB
- Tags: CPython 3.8+, manylinux: glibc 2.34+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
217cd7936e74722ecd91eafc6e16b63d96044e911a35f49fe7ff7b5d03572e5c
|
|
| MD5 |
dc9bc1e43ca538b6588cca23e031e67c
|
|
| BLAKE2b-256 |
985ec8fc17cc2da43e26451630e5a23ae5ca26767f9fcb6f0c2a3f2adf1ef5c0
|
File details
Details for the file polars_japanese-0.1.2-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: polars_japanese-0.1.2-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.0 MB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0fa0828f5a767d89332d88ff90ca6dea6ac582aab0e6073b5a57dd03704a112
|
|
| MD5 |
dc540ec9f484c7dcf94d37fbd5346ea8
|
|
| BLAKE2b-256 |
cfc191b27ff8734942e5e10a4743c5ad73d6bc7ab28668c091235d5ab3574518
|