Description
Code Sample, a copy-pastable example if possible
import pandas as pd
pd.DataFrame([
{'A':'a', 'B':'b'}
]).groupby(
['A','B']
).apply(
lambda x: x.to_dict(orient='records')
).to_json()
produces an invalid JSON string:
'{"["a","b"]":[{"A":"a","B":"b"}]}'
Problem description
For the given transformation, the output of to_json
of a pandas.core.series.Series
is not a valid JSON object.
Would be nice if it was.
Expected Output
'{"[\'a\',\'b\']":[{"A":"a","B":"b"}]}'
Output of pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.5.final.0
python-bits : 64
OS : Linux
OS-release : 4.19.84
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 0.25.2
numpy : 1.17.3
pytz : 2019.3
dateutil : 2.8.0
pip : None
setuptools : None
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.4.1
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : None
IPython : 7.8.0
pandas_datareader: None
bs4 : 4.8.1
bottleneck : 1.2.1
fastparquet : None
gcsfs : None
lxml.etree : 4.4.1
matplotlib : None
numexpr : 2.7.0
odfpy : None
openpyxl : 3.0.0
pandas_gbq : None
pyarrow : None
pytables : None
s3fs : None
scipy : 1.3.1
sqlalchemy : 1.3.10
tables : None
xarray : None
xlrd : 1.2.0
xlwt : 1.3.0
xlsxwriter : None