pandas.io.json.build_table_schema#

pandas.io.json.build_table_schema(data, index=True, primary_key=None, version=True)[源代码]#

从以下位置创建表架构 data

参数
data系列,DataFrame
index布尔值,默认为True

是否包括 data.index 在架构中。

primary_keyBool或None,默认为True

要指定为主键的列名。默认设置 None 将设置 'primaryKey' 如果索引是唯一的,则设置为一个或多个索引级别。

version布尔值,默认为True

是否包含字段 pandas_version 上一次修改表架构的Pandas版本。此版本可以与已安装的Pandas版本不同。

退货
schemaDICT

注意事项

看见 Table Schema 用于换算类型。Timedeltas转换为ISO8601持续时间格式,秒字段后有9个小数位,以实现纳秒精度。

范畴词被转换为 any 数据类型,并使用 enum 字段约束以列出允许值。这个 ordered 属性包含在 ordered 田野。

示例

>>> 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'}