Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: using 2 character seperator in pd.json_normalize #43831

Closed
2 of 3 tasks
pustetorte opened this issue Oct 1, 2021 · 2 comments · Fixed by #43851
Closed
2 of 3 tasks

BUG: using 2 character seperator in pd.json_normalize #43831

pustetorte opened this issue Oct 1, 2021 · 2 comments · Fixed by #43851
Assignees
Labels
Bug IO JSON read_json, to_json, json_normalize
Milestone

Comments

@pustetorte
Copy link

pustetorte commented Oct 1, 2021

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the master branch of pandas.

Reproducible Example

import pandas as pd
d = {'a': [1, 2], 'b': {'b_1': 2, 'b_2': (3, 4)}}
r = pd.json_normalize(d, sep='__')

Issue Description

When using a separator with more then 1 character, for example '__', the new column names get the separator as prefix, too. If you use a separator with only 1 character, for example '_', everything works fine.

I get the following output from the code provided:

    a      __b__b_1      __b__b_2
 0  [1, 2]      2         (3, 4)

Expected Behavior

    a      b__b_1      b__b_2
 0  [1, 2]     2       (3, 4)

Installed Versions

INSTALLED VERSIONS

commit : 73c6825
python : 3.9.6.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18363
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 9, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : de_DE.cp1252
pandas : 1.3.3
numpy : 1.21.1
pytz : 2021.1
dateutil : 2.8.2
pip : 21.2.4
setuptools : 49.6.0.post20210108
Cython : 0.29.24
pytest : 6.2.5
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.1
IPython : 7.26.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 2021.07.0
fastparquet : None
gcsfs : None
matplotlib : 3.4.2
numexpr : 2.7.3
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 1.0.1
pyxlsb : None
s3fs : 0.4.2
scipy : 1.7.1
sqlalchemy : 1.3.23
tables : 3.6.1
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@pustetorte pustetorte added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 1, 2021
@pustetorte
Copy link
Author

A workaround is to set record_prefix='', but I don't think, that this should be the solution.

@pustetorte pustetorte changed the title BUG: BUG: using 2 character seperator in pd.json_normalize Oct 1, 2021
@Vijay-Arora
Copy link

Hey @pustetorte, I am new to open source contribution; Could you please suggest me if I could help you with any of the things related to this issue? Would love to hear from you!
Thanks!

@debnathshoham debnathshoham added the IO JSON read_json, to_json, json_normalize label Oct 1, 2021
@mroeschke mroeschke removed the Needs Triage Issue that has not been reviewed by a pandas team member label Oct 2, 2021
@debnathshoham debnathshoham self-assigned this Oct 2, 2021
@jreback jreback added this to the 1.4 milestone Oct 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO JSON read_json, to_json, json_normalize
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants