Using python 3.5我有一个形式的输出文件:
result =
[{'alt': '',
'company_id': 309,
'confidence': 0,
'person_id': 17591,
'person_image_url': '',
'person_name': 'abc'},
{'alt': '',
'company_id': 309,
'confidence': 0,
'person_id': 20298,
'person_image_url': '',
'person_name': 'def'},
{'alt': '',
'company_id': 309,
'confidence': 0,
'person_id': 20301,
'person_image_url': '',
'person_name': 'ghi'}]
如何使用以下格式将其另存为 CSV 文件:
alt company_id confidence person_id person_image_url person_name
309 0 17591 '' abc
309 0 20298 '' def
309 0 20301 '' ghi
import pandas as pd
df = pd.DataFrame(result)
df.to_csv('result.csv', index=False, sep='t')
您可以使用
包pandas
:
import pandas as pd
df = pd.DataFrame(result)
print(df)
df.to_csv('result.csv', index=False, sep=';')