【发布时间】:2019-09-01 08:52:42
【问题描述】:
我的问题是关于如何从列表列表中创建字典列表,并且与这个问题Dict Comprehension python from list of lists 和这个问题List of Lists to List of Dictionaries 有偏差
我有一个很长的熊猫数据框,其中包含经纬度
LAT LON
40 5
40 6
41 5
42 8
42 9
我设法将其转换为带有 towers.values 的列表列表(towers 是数据框的名称),其中每个列表的格式为 [lat,lon]
我的目标是拥有
list_dict = [{'lat': 40, 'lon': 5},
{'lat': 40, 'lon': 6},
{'lat': 41, 'lon': 5},
{'lat': 41, 'lon': 5},
{'lat': 42, 'lon': 8},
{'lat': 42, 'lon': 9}]
我该怎么做?
【问题讨论】:
-
别想了,试试
towers.to_dict(orient='records')
标签: python python-3.x pandas list dictionary