[英]How do I export data in a PyCharm file into an Excel sheet?
I have some code in PyCharm that gets me a lot of data and I would like to create an Excel sheet with all of the data.我在 PyCharm 中有一些代码可以获取大量数据,我想创建一个包含所有数据的 Excel 工作表。
I've already tried renaming the file and saving it with ".xlsx" instead of ".py" but that didn't work.我已经尝试重命名文件并使用“.xlsx”而不是“.py”保存它,但这没有用。
Listed below is my code and the data I want to export into an Excel sheet.下面列出的是我的代码和我想导出到 Excel 工作表中的数据。
Code:代码:
import requests
url1 = 'https://domain.zendesk.com/api/v2/incremental/tickets.json?
start_time=1561939200&include=metric_sets'
url2 = 'https://domain.zendesk.com/api/v2/ticket_metrics.json'
user = 'email' + '/token'
pwd = 'token'
response1 = requests.get(url1, auth=(user, pwd))
response2 = requests.get(url2, auth=(user, pwd))
data1 = response1.json()
data2 = response2.json()
ticket_list1 = data1['tickets']
ticket_list2 = data2['ticket_metrics']
for ticket1 in ticket_list1:
for ticket2 in ticket_list2:
if ticket1['assignee_id'] != ticket1['requester_id']:
print(ticket2['reply_time_in_minutes'])
print(ticket1['assignee_id'])
print(ticket2['ticket_id'])
Example data I want to export:我要导出的示例数据:
{'calendar': 3, 'business': 3}
363041385813
52629
{'calendar': None, 'business': None}
363041385813
52628
{'calendar': 11, 'business': 11}
363041385813
52627
You can't convert .py
to .xlsx
.您不能将
.py
转换为.xlsx
。 You can, however, create a secondary file called foo.xlsx
and apply your results to it.但是,您可以创建一个名为
foo.xlsx
的辅助文件并将您的结果应用于它。 To apply in a single row you can probably use要在单行中申请,您可能可以使用
a = open("foo.xlsx", "a")
a.write(result)
But I haven't worked with .xlsx
files so you'll have to research how to append to multiple rows.但我没有使用过
.xlsx
文件,所以你必须研究如何附加到多行。
I figured it out.我想到了。 All you have to do is run the program in PyCharm, copy the program file location, and paste it into the terminal and add this at the end "> ~/Desktop/anyname.csv"
您所要做的就是在 PyCharm 中运行程序,复制程序文件位置,然后将其粘贴到终端并在末尾添加“> ~/Desktop/anyname.csv”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.