Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix to #62205
  • Loading branch information
PluvioXO committed Sep 11, 2025
commit b4337e26ab80b57768c71e6bbb13feb32946de44
5 changes: 4 additions & 1 deletion pandas/io/json/_normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,10 @@ def _pull_records(js: dict[str, Any], spec: list | str) -> list:
# TODO: handle record value which are lists, at least error
# reasonably
data = nested_to_record(data, sep=sep, max_level=max_level)
return DataFrame(data, index=index)
result = DataFrame(data, index=index)
if record_prefix is not None:
result = result.rename(columns=lambda x: f"{record_prefix}{x}")
return result
elif not isinstance(record_path, list):
record_path = [record_path]

Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/io/json/test_normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,15 @@ def test_record_prefix(self, state_data):

tm.assert_frame_equal(result, expected)

def test_record_prefix_no_record_path_series(self):
# Ensure record_prefix is applied when record_path is None for Series input
s = Series([{"k": f"{i}", "m": "q"} for i in range(3)])
result = json_normalize(s, record_prefix="T.")
expected = DataFrame(
[{"T.k": "0", "T.m": "q"}, {"T.k": "1", "T.m": "q"}, {"T.k": "2", "T.m": "q"}]
)
tm.assert_frame_equal(result, expected)

def test_non_ascii_key(self):
testjson = (
b'[{"\xc3\x9cnic\xc3\xb8de":0,"sub":{"A":1, "B":2}},'
Expand Down
Loading