Skip to content

Table Schema with MultiIndex includes unnescessary field #16203

Closed
@TomAugspurger

Description

@TomAugspurger
In [11]: df = pd.DataFrame(np.random.randn(4, 4),
    ...:                 columns=pd.MultiIndex.from_product([('A', 'B'),
    ...:                                                  ('a', 'b')]))
    ...: df
    ...:
Out[11]:
          A                   B
          a         b         a         b
0  0.483942 -0.888943 -0.501563  1.688760
1  0.943328  0.487903 -0.310336  0.602214
2  0.261042 -1.753800  0.000682  1.439406
3 -0.571016 -0.763698  2.441181  0.109586

In [12]: build_table_schema(df.T)
Out[12]:
{'fields': [{'name': 'level_0', 'type': 'string'},
  {'name': 'level_1', 'type': 'string'},
  {'name': 'values', 'type': 'number'},  # this is wrong
  {'name': 1, 'type': 'number'},
  {'name': 2, 'type': 'number'},
  {'name': 3, 'type': 'number'}],
 'pandas_version': '0.20.0',
 'primaryKey': FrozenList(['level_0', 'level_1'])}

Will try to get to this now.

Metadata

Metadata

Assignees

No one assigned

    Labels

    IO JSONread_json, to_json, json_normalizeOutput-Formatting__repr__ of pandas objects, to_string

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions