Skip to content

to_json() for multi indexed dataframe is missing escapes #27045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dickreuter opened this issue Jun 26, 2019 · 1 comment
Closed

to_json() for multi indexed dataframe is missing escapes #27045

dickreuter opened this issue Jun 26, 2019 · 1 comment
Labels
Duplicate Report Duplicate issue or pull request IO JSON read_json, to_json, json_normalize MultiIndex

Comments

@dickreuter
Copy link
Contributor

For df.to_json() the speech marks should be escaped. Currently, the json is not valid. This was already reported as an issue here #15288, but most likely incorrectly marked as duplicate with something else.

idx = pd.MultiIndex.from_product([['Zara', 'LV', 'Roots'],
                                  ['Orders', 'GMV', 'AOV']],
                                 names=['Brand', 'Metric'])
col = ['Yesterday', 'Yesterday-1', 'Yesterday-7', 'Thirty day average']

df = pd.DataFrame('-', idx, col)
df.to_json()

'{"Yesterday":{"["Zara","Orders"]":"-","["Zara","GMV"]":"-","["Zara","AOV"]":"-","["LV","Orders"]":"-","["LV","GMV"]":"-","["LV","AOV"]":"-","["Roots","Orders"]":"-","["Roots","GMV"]":"-","["Roots","AOV"]":"-"},"Yesterday-1":{"["Zara","Orders"]":"-","["Zara","GMV"]":"-","["Zara","AOV"]":"-","["LV","Orders"]":"-","["LV","GMV"]":"-","["LV","AOV"]":"-","["Roots","Orders"]":"-","["Roots","GMV"]":"-","["Roots","AOV"]":"-"},"Yesterday-7":{"["Zara","Orders"]":"-","["Zara","GMV"]":"-","["Zara","AOV"]":"-","["LV","Orders"]":"-","["LV","GMV"]":"-","["LV","AOV"]":"-","["Roots","Orders"]":"-","["Roots","GMV"]":"-","["Roots","AOV"]":"-"},"Thirty day average":{"["Zara","Orders"]":"-","["Zara","GMV"]":"-","["Zara","AOV"]":"-","["LV","Orders"]":"-","["LV","GMV"]":"-","["LV","AOV"]":"-","["Roots","Orders"]":"-","["Roots","GMV"]":"-","["Roots","AOV"]":"-"}}'

`

@jreback
Copy link
Contributor

jreback commented Jun 26, 2019

and if u see the issue you pointed references an open issue

#15273

@jreback jreback closed this as completed Jun 26, 2019
@jreback jreback added Duplicate Report Duplicate issue or pull request IO JSON read_json, to_json, json_normalize MultiIndex labels Jun 26, 2019
@jreback jreback added this to the No action milestone Jun 26, 2019
felixDulys added a commit to felixDulys/pandas that referenced this issue Aug 8, 2021
felixDulys added a commit to felixDulys/pandas that referenced this issue Aug 8, 2021
felixDulys added a commit to felixDulys/pandas that referenced this issue Aug 9, 2021
felixDulys added a commit to felixDulys/pandas that referenced this issue Aug 9, 2021
felixDulys added a commit to felixDulys/pandas that referenced this issue Aug 9, 2021
felixDulys added a commit to felixDulys/pandas that referenced this issue Aug 10, 2021
felixDulys added a commit to felixDulys/pandas that referenced this issue Aug 11, 2021
felixDulys added a commit to felixDulys/pandas that referenced this issue Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request IO JSON read_json, to_json, json_normalize MultiIndex
Projects
None yet
Development

No branches or pull requests

2 participants