【发布时间】:2022-01-19 02:04:14
【问题描述】:
我在下面有一个熊猫数据框:
df_input = pd.DataFrame({
'Domain':['www.google.com','www.apple.com','www.amazon.com'],
'Description':['The company’s product portfolio includes Googl...','Apple is a multinational corporation that desi...','Amazon is an international e-commerce website ...'],
'About Us':['Google is a multinational corporation that spe...','Apple is a multinational corporation that desi...','Amazon is an e-commerce website for consumers,...'],
'Founded':[1998, 1976, 1994],
'Country':['United States','United States','United States']})
我想按如下方式传输:
[{"properties": [{"name": "Description","value": "The company’s product portfolio includes Google Search, which provides users with access to information online; Knowledge Graph that allows users to search for things, people, or places as well as builds systems recognizing speech and understanding"},
{"name": "Domain","value": "www.google.com"},
{"name": "About Us", "value": "Google is a multinational corporation that specializes in Internet-related services and products."},
{"name": "Founded", "value": 1998},
{"name": "Country", "value":"United States"}]},
{"properties": [{"name": "Description","value": "Apple is a multinational corporation that designs, manufactures, and markets mobile communication and media devices, personal computers, portable digital music players, and sells a variety of related software, services, peripherals, networking solutions, and third-party digital content and applications."},
{"name": "Domain","value": "www.apple.com"},
{"name": "About Us", "value": "Apple is a multinational corporation that designs, manufactures, and markets consumer electronics, personal computers, and software."},
{"name": "Founded", "value": 1976},
{"name": "Country", "value":"United States"}]},
{"properties": [{"name": "Description","value": "Amazon is an international e-commerce website for consumers, sellers, and content creators. It offers users merchandise and content purchased for resale from vendors and those offered by third-party sellers."},
{"name": "Domain","value": "www.amazon.com"},
{"name": "About Us", "value": "Amazon is an e-commerce website for consumers, sellers, and content creators."},
{"name": "Founded", "value": 1994},
{"name": "Country", "value":"United States"}]}]
如何编写循环来执行此操作?
【问题讨论】:
标签: python pandas dataframe loops dictionary