Pandas-like toolkit for nested JSON/NDJSON: flatten, select, explode, reconstruct
Project description
nestedframe
面向嵌套 JSON/NDJSON 的 Pandas 风格数据工具。目标是让处理半结构化的事件日志、API 响应、埋点、NDJSON 文件像用 Pandas 一样顺畅:一行载入、路径选择、受控扁平化、数组爆炸、再构造成嵌套结构。
-
痛点:
json_normalize很快失控,数组字段处理复杂,丢层级关系。- 需要在“保留原始嵌套结构”与“产生可分析的扁平表”之间来回切换。
- 选择嵌套字段、匹配多层路径、对数组进行受控 explode 并保持父子关联很麻烦。
-
解决:
NestedFrame提供from_records、select('user.*')、explode('items')、to_nested(group_by='_root_id')等 API。- 列名采用点路径表示,如
user.id、meta.country,数组 explode 时自动展开子字段为items.id、items.qty。
安装
pip install -e .
快速上手
from nestedframe import NestedFrame
records = [
{"user": {"id": 1, "name": "A"}, "items": [{"id": "i1", "qty": 2}, {"id": "i2", "qty": 1}], "meta": {"country": "CN"}},
{"user": {"id": 2, "name": "B"}, "items": [{"id": "i3", "qty": 5}], "meta": {"country": "US"}}
]
nf = NestedFrame.from_records(records)
df = nf.to_pandas()
nf2 = nf.explode("items")
exploded = nf2.to_pandas()
nested = nf2.to_nested(group_by="_root_id")
主要 API
NestedFrame.from_records(records)载入嵌套数据select(patterns)支持fnmatch风格的路径筛选,如user.*、meta.countryexplode(path)对数组字段受控爆炸,并将子字段扁平为点路径to_pandas()获取扁平化 DataFrameto_nested(group_by=None)将表再构造成嵌套记录;当使用过explode时建议按_root_id分组
适用场景
- 大量 NDJSON 事件日志分析
- API 响应批量整形、聚合和统计
- 埋点数据质量分析与快速探索
许可
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
nestedframe-0.1.0.tar.gz
(6.8 kB
view details)
Built Distribution
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 nestedframe-0.1.0.tar.gz.
File metadata
- Download URL: nestedframe-0.1.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3bbd54af19604bc8ece35d7a8db23531c111a00c8f71fddcb278d51b8bed5c6
|
|
| MD5 |
7e478a5a10c953b6c3bdaa439b8f50e5
|
|
| BLAKE2b-256 |
674a9b3110515c994e3f8e6978b26f309439e9aee2d409df32deb35c6ac8d0ca
|
File details
Details for the file nestedframe-0.1.0-py3-none-any.whl.
File metadata
- Download URL: nestedframe-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9990a16d9d69b6fdadd23e6a9cc7a4241a093c42264c7c570cdca60a79f1b64
|
|
| MD5 |
fce266c71d268cd0bb55466ddadb73ee
|
|
| BLAKE2b-256 |
97563828b0fd2c6bd4a904ca4380c1b015a38314741e0629454fae88f18da4f8
|