将打印结果从Python导出到csv或excel

muk1a3rh  于 2023-06-19  发布在  Python
关注(0)|答案(1)|浏览(125)

enter image description here

from jira import JIRA, JIRAError
import numpy as np
import pandas as pd
import networkx as nx
import csv
import xlsxwriter 

jiraOptions = {'server': "https://jira.server_link"}
jira = JIRA(options=jiraOptions, basic_auth=("my Jira user ID", "my Jira password"))
df = jira.search_issues('filter=myJira # filter', startAt=block_num*block_size, maxResults=block_size, fields="*")
block_size = 10000
block_num = 0

print(df)

df.to_csv(path_or_buf='data.csv', sep=';', header=header, index=True, index_label='N', mode=mode) -> Error:AttributeError: 'ResultList' object has no attribute 'to_csv


亲爱的社区,
你知道如何修复这个错误吗?我需要将过滤器Jira结果打印到csv/excel。有什么想法吗?
谢谢你

toiithl6

toiithl61#

IIUC,您最可能需要Search of Issues结果的表格格式:

search_result = jira.search_issues(
    "filter=myJira # filter", startAt=block_num*block_size,
    maxResults=block_size, fields="*"
)

data = [
    [issue.key, issue.id, issue.fields.assignee, issue.fields.status,
     issue.fields.summary, issue.fields.created, issue.fields.updated]
    for issue in search_result
]

header = ["Key", "Id", "Assignee", "Status", "Summary", "Created", "Updated"]

df = pd.DataFrame(data, columns=header)

测试/输出:
适用范围:

search_result = jira.search_issues("Project=JPOSERVER") # jira.projects()[0]

我们得到:

print(df)

            Key       Id Assignee       Status      Summary      Created      Updated
0   JPOSERVE...  1952906     None  Needs Tr...  Document...  2023-06-...  2023-06-...
1   JPOSERVE...  1953011     None  Gatherin...  Thanks f...  2023-06-...  2023-06-...
2   JPOSERVE...  1952899     None  Gatherin...  allow al...  2023-06-...  2023-06-...
..          ...      ...      ...          ...          ...          ...          ...
47  JPOSERVE...  1950141     None       Closed  Cryogen ...  2023-05-...  2023-06-...
48  JPOSERVE...  1950118     None       Closed  Trump's ...  2023-05-...  2023-06-...
49  JPOSERVE...  1949963     None       Closed  Alpha Bi...  2023-05-...  2023-06-...

[50 rows x 7 columns]

相关问题