json_normalize - incorrect removing separator from beginning of key · Issue #49861 · pandas-dev/pandas (original) (raw)

print(pd.__version__)
jsn={'_id':{'a1':10,"l2":{"l3":0}}, "gg":4}
display(pd.json_normalize(jsn,sep='_'))

Actual result:

1.5.2

gg id_a1 id_l2_l3
4 10 0

Expected result:
the "_" prefix should not be removed from the beginning of the column names.

1.5.2

gg _id_a1 _id_l2_l3
4 10 0

This issue was introduced with the following change:
https://github.com/pandas-dev/pandas/pull/40035/files