Skip to content

Commit d77a2a2

Browse files
committed
PERF: 5x speedup for read_json() with orient='index' by avoiding transpose
1 parent 65e123c commit d77a2a2

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pandas/io/json/_json.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,9 +1085,11 @@ def _parse_no_numpy(self):
10851085
self.check_keys_split(decoded)
10861086
self.obj = DataFrame(dtype=None, **decoded)
10871087
elif orient == "index":
1088-
self.obj = DataFrame(
1089-
loads(json, precise_float=self.precise_float), dtype=None
1090-
).T
1088+
self.obj = DataFrame.from_dict(
1089+
loads(json, precise_float=self.precise_float),
1090+
dtype=None,
1091+
orient="index",
1092+
).sort_index(axis="columns")
10911093
elif orient == "table":
10921094
self.obj = parse_table_schema(json, precise_float=self.precise_float)
10931095
else:

0 commit comments

Comments
 (0)