pandas.io.json.build_table_schema#
- pandas.io.json.build_table_schema(data, index=True, primary_key=None, version=True)[源代码]#
从
data创建 Table schema。- Parameters:
- dataSeries, DataFrame
- indexbool, default True
是否在 schema 中包含
data.index。- primary_keybool 或 None,默认为 True
指定为主键的列名。默认值 None 将 ‘primaryKey’ 设置为索引级别或级别,前提是索引是唯一的。
- versionbool, default True
是否包含一个 pandas_version 字段,显示最后修改表 schema 的 pandas 版本。此版本可能与安装的 pandas 版本不同。
- Returns:
- dict
Notes
有关转换类型,请参阅 Table Schema 。Timedeltas 被转换为 ISO8601 持续时间格式,在秒字段后有 9 位小数以实现纳秒精度。
Categoricals 被转换为 any dtype,并使用 enum 字段约束列出允许的值。ordered 属性包含在 ordered 字段中。
Examples
>>> from pandas.io.json._table_schema import build_table_schema >>> df = pd.DataFrame( ... {'A': [1, 2, 3], ... 'B': ['a', 'b', 'c'], ... 'C': pd.date_range('2016-01-01', freq='d', periods=3), ... }, index=pd.Index(range(3), name='idx')) >>> build_table_schema(df) {'fields': [{'name': 'idx', 'type': 'integer'}, {'name': 'A', 'type': 'integer'}, {'name': 'B', 'type': 'string'}, {'name': 'C', 'type': 'datetime'}], 'primaryKey': ['idx'], 'pandas_version': '1.4.0'}