简体   繁体   中英

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.

I've already tried renaming the file and saving it with ".xlsx" instead of ".py" but that didn't work.

Listed below is my code and the data I want to export into an Excel sheet.

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 . You can, however, create a secondary file called foo.xlsx and apply your results to it. 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.

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM