Skip to content

Commit 5edd63c

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

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

pandas/io/json/_json.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,9 +1085,15 @@ 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 = (
1089+
DataFrame.from_dict(
1090+
loads(json, precise_float=self.precise_float),
1091+
dtype=None,
1092+
orient="index",
1093+
)
1094+
.sort_index(axis="columns")
1095+
.sort_index(axis="index")
1096+
)
10911097
elif orient == "table":
10921098
self.obj = parse_table_schema(json, precise_float=self.precise_float)
10931099
else:

0 commit comments

Comments
 (0)