Python 从熊猫数据框架到谷歌地图API的json文件

Python 从熊猫数据框架到谷歌地图API的json文件,python,json,pandas,google-maps-api-3,Python,Json,Pandas,Google Maps Api 3,我有一个有两列的数据框 Lat Long 0 53.0294 53.3256 1 13.6363 63.3632 2 22.5353 55.2201 ... 现在,我需要json文件来完美地用于GoogleMapAPI 看起来像这样: [{"Lat": "45.496275", "Long": "19.700225"} {"Lat": "43.9332040422", "Long": "21.3821478025"} {"Lat": "43.72

我有一个有两列的数据框

      Lat       Long
0   53.0294   53.3256
1   13.6363   63.3632
2   22.5353   55.2201
...
现在,我需要json文件来完美地用于GoogleMapAPI

看起来像这样:

[{"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}]
我不需要这些斜杠,我不确定是否可以在GoogleMapAPI的javascript代码中使用这些斜杠

您可以使用:

coord_frame.to_json('file.json', orient='records')
要将
dict
写入
文件
使用:

import json

out = coord_frame.to_dict(orient='records')

with open("file.json", 'w') as f:
    json.dump(out, f)

使用
df.命令('r')
?@Zero谢谢。)问题在于如何保存json。你们也可以添加那个些代码吗?但当我把它保存到txt时,我得到了那个些斜杠。我尝试了一些测试,添加了2个解决方案。不幸的是,我不能用反斜杠来模拟你的问题,但我希望它能很好地工作。