Skip to content

BUG: pd.json_normalize() does not handle index while working with Series #43304

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

Closed
3 tasks done
tommasogallingani opened this issue Aug 30, 2021 · 4 comments
Closed
3 tasks done
Labels
Closing Candidate May be closeable, needs more eyeballs IO JSON read_json, to_json, json_normalize Usage Question

Comments

@tommasogallingani
Copy link

tommasogallingani commented Aug 30, 2021

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

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

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


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

pd.json_normalize(test_data['mycol'])
import pandas as pd
test_data =  pd.DataFrame([[{'a':1,'b':4,'c':0}],[ {'a':10,'b':10,'c':10}],[{'a':0,'b':0,'c':0}]], index=[5,2,3], columns=['mycol'])
pd.json_normalize(test_data['mycol'])

	a	b	c
0	1	4	0
1	10	10	10
2	0	0	0

Problem description

When a Series is passed to json_normalize the function returns a re-indexed dataframe without taking into account the index passed through the Series. This beahaviour is absolutely unexpected while working with Series

Expected Output

	a	b	c
5	1	4	0
2	10	10	10
3	0	0	0

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 3e89b4c
python : 3.8.5.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19041
machine : AMD64
processor : Intel64 Family 6 Model 158 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : Italian_Italy.1252

pandas : 1.2.0
numpy : 1.19.5
pytz : 2021.1
dateutil : 2.8.2
pip : 20.3.3
setuptools : 51.1.2.post20210112
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.8.6 (dt dec pq3 ext lo64)
jinja2 : 3.0.1
IPython : 7.26.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 0.8.5
fastparquet : None
gcsfs : None
matplotlib : 3.3.3
numexpr : None
odfpy : None
openpyxl : 3.0.6
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : 0.5.2
scipy : 1.6.0
sqlalchemy : 1.3.22
tables : None
tabulate : None
xarray : None
xlrd : 1.2.0
xlwt : None
numba : None

@tommasogallingani tommasogallingani added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 30, 2021
@phofl
Copy link
Member

phofl commented Aug 30, 2021

data is supposed to be a list or a dict, not a Series. So this is expected.

on a related note: I am not able to find the docs after 1.2.5, can anybody double check please?

@asishm
Copy link
Contributor

asishm commented Aug 30, 2021

on a related note: I am not able to find the docs after 1.2.5, can anybody double check please?

possibly xref #42540

@phofl
Copy link
Member

phofl commented Aug 30, 2021

Should have checked, thx

@phofl phofl added Closing Candidate May be closeable, needs more eyeballs IO JSON read_json, to_json, json_normalize Usage Question and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Aug 30, 2021
@mroeschke
Copy link
Member

Closing as the expected behavior

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Closing Candidate May be closeable, needs more eyeballs IO JSON read_json, to_json, json_normalize Usage Question
Projects
None yet
Development

No branches or pull requests

4 participants