I have a Pandas DataFrame that I need to convert to JSON. The to_json() DataFrame method results in an acceptable format, but it converts my DataFrame index to strings (e.g. 0 becomes "0.0"). I need "0".
The DataFrame comes from JSON using the pd.io.json.read_json() method, which sets the index to float64.
Input JSON:
{"chemical": {"1": "chem2", "0": "chem1"},
"type": {"1": "pesticide", "0": "pesticide"}}
DataFrame (from read_json()):
chemical type
0 chem1 pesticide
1 chem2 pesticide
Produced JSON (from to_json()):
{"chemical": {"0.0": "chem1", "1.0": "chem2"},
"type": {"0.0": "pesticide", "1.0": "pesticide"}}
Needed JSON:
{"chemical": {"0": "chem1", "1": "chem2"},
"type": {"0": "pesticide", "1": "pesticide"}}