我有1500个JSON格式的元素,但我需要放入python字典中。每个元素都与一个ID相关联(ID也在字典中,是一个多边形表示形式)。
这些元素具有相同的结构:
OrderedDict([('d5b6d112-903b-4648-833e-d7c3fdac490b',
{'title': 'S2A_MSIL1C_20200410T105031_N0209_R051_T31TCF_20200410T112156',
'link': "https://scihub.copernicus.eu/dhus/odata/v1/Products('d5b6d112-903b-4648-833e-d7c3fdac490b')/$value",
'link_alternative': "https://scihub.copernicus.eu/dhus/odata/v1/Products('d5b6d112-903b-4648-833e-d7c3fdac490b')/",
'link_icon': "https://scihub.copernicus.eu/dhus/odata/v1/Products('d5b6d112-903b-4648-833e-d7c3fdac490b')/Products('Quicklook')/$value",
'summary': 'Date: 2020-04-10T10:50:31.024Z, Instrument: MSI, Mode: , Satellite: Sentinel-2, Size: 708.56 MB',
'datatakesensingstart': datetime.datetime(2020, 4, 10, 10, 50, 31, 24000),
'beginposition': datetime.datetime(2020, 4, 10, 10, 50, 31, 24000),
'endposition': datetime.datetime(2020, 4, 10, 10, 50, 31, 24000),
'ingestiondate': datetime.datetime(2020, 4, 10, 15, 23, 51, 463000),
'orbitnumber': 25073,
'relativeorbitnumber': 51,
'cloudcoverpercentage': 25.1653,
'sensoroperationalmode': 'INS-NOBS',
'gmlfootprint': '<gml:Polygon srsName="http://www.opengis.net/gml/srs/epsg.xml#4326" xmlns:gml="http://www.opengis.net/gml">\n <gml:outerBoundaryIs>\n <gml:LinearRing>\n <gml:coordinates>41.12630256662179,1.925343307665624 41.0388866778506,1.893218517758493 40.89259720303277,1.839655652731482 40.74637877387899,1.786307008717412 40.60020137146172,1.733323787214736 40.554608185948275,1.716936587906194 40.538607851727775,0.638419022640916 41.52685230149302,0.6028173807795 41.546758769895376,1.918508192616414 41.12630256662179,1.925343307665624</gml:coordinates>\n </gml:LinearRing>\n </gml:outerBoundaryIs>\n</gml:Polygon>',
'footprint': 'MULTIPOLYGON (((0.638419022640916 40.538607851727775, 1.716936587906194 40.554608185948275, 1.733323787214736 40.60020137146172, 1.786307008717412 40.74637877387899, 1.839655652731482 40.89259720303277, 1.893218517758493 41.0388866778506, 1.925343307665624 41.12630256662179, 1.918508192616414 41.546758769895376, 0.6028173807795 41.52685230149302, 0.638419022640916 40.538607851727775)))',
我需要摘录:标题,足迹和数据采集开始。我希望所有提取的元素都存储在列表中。
非常感谢!
extracted = {}
for elem in list_of_elems:
extracted[elem[0]] = {
k:elem[k]
for k in ('title', 'footprint', 'datatakesensingstart')
}
给出具有您提到的结构的OrderedDict
对象的列表,您可以使用列表推导来创建精简字典的列表,该字典仅包含您感兴趣的键。
trimmed_data = [
{
'Title': element[1]['Title'],
'footprint': element[1]['footprint'],
'datatakesensingstart': element[1]['datatakesensingstart'],
}
for element in data
]