question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Json import sorting

See original GitHub issue

Noticed that if export a df to json file and then reload the data, ordering is not kept.

import pandas as pd

df.to_json('test.json')
newdf = pd.read_json('test.json')

print df.index

gives:

1
10
100
....

instead of

1
2
3
....

it suffices to call newdf = pd.read_json('test.json').sort() to have the what I’d expect.

Is this intended behaviour or bug?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:22 (22 by maintainers)

github_iconTop GitHub Comments

2reactions
Komnomnomnomcommented, Aug 29, 2013

BTW @ghego if you want to ensure that order is preserved during roudtrip JSONifying try using orient=split

n [27]: pd.read_json(df.to_json(orient='split'), orient='split')
[0]
Out[27]: 
     foo
1      1
2      2
3      3
4     10
10    11
11    20
100  100
101  101

0reactions
Komnomnomnomcommented, Oct 21, 2013

@jreback #5287 eventually got there. Thanks for the reminders.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to sort JSON objects in Python - Linux Hint
The JSON object can be sorted by using built-in python functions, modules, and user-defined functions. ... Import the JSON module import json
Read more >
sort-json - npm
Takes a json-file and return a copy of the same file, but sorted. Latest version: 2.0.1, last published: 10 months ago.
Read more >
Sort data when using ImportJSON - Stack Overflow
You can't sort data before you load it, the original data is in JSON format anyways. JSON contains a un-ordered collection of name/value...
Read more >
Sorting your imports with ESLint - DEV Community ‍ ‍
Package imports should come next, sorted by alphabetical order; The named imports should be sorted in alphabetical order; It should skip a line ......
Read more >
Python | Sort JSON by value - GeeksforGeeks
The task is to sort the JSON first by code, then by grade and then by enrollment_no . Code #1: Sorting in Desc...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found