I have a pandas dataframe and want to convert it to json format.
import pandas as pd
df = pd.DataFrame({'A': [1,2,3,4], 'B': [5,6,7,8]})
df.to_json()
'{"A":{"0":1,"1":2,"2":3,"3":4},"B":{"0":5,"1":6,"2":7,"3":8}}'
The json string I need is like below:
'{"A":[1,2,3,4], "B":[5,6,7,8]}'
How can I get this json string from pandas dataframe? Thanks a lot.