我有一个包含两列的 pandas 数据框
Lat Long
0 53.0294 53.3256
1 13.6363 63.3632
2 22.5353 55.2201
...
现在我需要 json 文件才能完美地用于 Google Map API。
看起来像这样:
[{"Lat": "45.496275", "Long": "19.700225"}
{"Lat": "43.9332040422", "Long": "21.3821478025"}
{"Lat": "43.7236250523", "Long": "20.6935022429"}]
我试过这个:
out = coord_frame.to_json(orient='records')
昂得到这个:
[{\"Lat\":44.8242557024,\"Long\":20.4048512901},{\"Lat\":44.8242557024,\"Long\":20.4048512901}]
我不需要那些斜杠,我不确定我是否可以在 Google Map API 的 javascript 代码中使用它。
请您参考如下方法:
您可以使用:
coord_frame.to_json('file.json', orient='records')
要将 dict 写入 file 使用:
import json
out = coord_frame.to_dict(orient='records')
with open("file.json", 'w') as f:
json.dump(out, f)
