简体   繁体   English

如何将 PyCharm 文件中的数据导出到 Excel 工作表中?

[英]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.

相关问题 如何使用Pandas将python Web抓取数据导出到现有excel文件中的特定工作表? - How can I export my python web scrape data to a specific sheet in an existing excel file using pandas? 如何为 Excel 文件中的每个工作表创建多个 DataFrame? - How do I create several DataFrames for each sheet in an Excel file? 如何将这个 pandas 数组的股票数据导出到 excel 电子表格中? - How do I export this pandas array of stock data into an excel spreadsheet? 如何将我的列表导出到 excel 兼容文件中? - how do I export my lists into an excel compatible file? 如何使用 Python 从多个文本文件中提取数据到 Excel? (每张纸一个文件的数据) - How do I extract data from multiple text files to Excel using Python? (One file's data per sheet) 如何将数据帧导出到每个 Excel 表 - how can I export dataframes to each Excel sheet 将数据从 Python 导出到 excel 表 - Export data from Python to an excel sheet 如何将 excel 文件中的数据导出到脚本 - How to export data from excel file to script 如何将dicom数据集导出为ex​​cel? - How do I export dicom datasets to excel? Python:如何将 dataframe 导出到现有的 Excel 工作表但不创建新工作表 - Python: how can I export dataframe to existing Excel sheet but not creating a new sheet
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM