【发布时间】:2020-08-26 15:13:18
【问题描述】:
我一直在尝试了解如何使用网站 API 以及如何使用 get 方法从网站下载数据。
目前我有一本大字典,我正在尝试写入文件。
当我将它输出到一个文件时,它看起来像这样:
{"Tickets":[{"Project":"Test_Project", "TicketID":"1", "Title":"Title_1", "Reportedby":"User_1"},{"Project":"Test_Project", "TicketID":"2", "Title":"Title_2", "Reportedby":"User_2"}]}
如何将其输出到 Excel 文件?
我尝试过使用各种字符串格式,例如:
response_string = response_string[response_string.find("["):len(response_string)-1]
response_string = response_string[1:len(response_string)-1]
response_string = response_string.replace("},{","} , {")
response_array = response_string.split(" , ") + response_array
但我知道这不是正确的方式,因为文本中的逗号真的会搞砸。
谢谢, A.
【问题讨论】:
-
或许可以创建一个 pandas 数据框并保存为 excel/csv?
-
最好使用 Pandas DataFrame,然后保存到 excel 中。但是,如果您不想使用它,这可能会对您有所帮助。 pythonspot.com/save-a-dictionary-to-a-file
-
这能回答你的问题吗? Python Dictionary to CSV