Home > Blockchain >  Convert output to a Pandas dataframe
Convert output to a Pandas dataframe

Time:08-18

I have the below data from JIRA. I am trying to have this converted into a pandas Dataframe.

Here is my code:

from jira import JIRA

jiraOptions = {'server': 'https://**********.atlassian.net'}

jira = JIRA(options=jiraOptions, basic_auth=(
    '*******@gmail.com', '******************'))

project = 'project = GDI'

lista = []

for issue in jira.search_issues(jql_str=project):
        print('{} | {} | {} | {} {} | {} | {} | {} | {} | {} |'.format(issue.key,
                                                                    issue.fields.project.name,
                                                                    issue.fields.summary,
                                                                    issue.fields.issuetype,
                                                                    issue.fields.status,
                                                                    issue.fields.priority,
                                                                    issue.fields.reporter.displayName,
                                                                    issue.fields.created,
                                                                    issue.fields.assignee,                                     
                                                                    issue.fields.description,))

Expected output :

issue key:      Project name:       summary:               issue type:     assignee:
GDI-6           PROJECTBLABLA       Summaryblabla          epictodo        Nova
GDI-5           PROJECTBLABLA       Summaryblabla          epictodo        Nova
GDI-4           PROJECTBLABLA       Summaryblabla          epictodo        Nova
GDI-3           PROJECTBLABLA       Summaryblabla          epictodo        Nova

Is there a smart way to do it? I'm really stuck.. All what I know is that I need a list for that, right? So I need to put every details into their corresponding list, instead of printing them, then I work on pandas.

Thanks in advance,

Nova

CodePudding user response:

I am not too sure if this solves your problem:

lista = []
for issue in jira.search_issues(jql_str=project):
   lista.append([issue.key, issue.fields.project.name, issue.fields.summary ...])

Then you can make a dataframe from this.

df = pd.DataFrame(lista)
df.columns = ['issue key:', 'Project name:', 'summary:' ...]

CodePudding user response:

Here is the output of my code:

DI-6 | Data Integration | Create Jenkins Job to automatise the collect of data  | Task To Do | Medium | Nova | 2022-07-04T12:10:03.155 0000 | Nova | Create Jenkins Job to automatise the collect of data daily |
DI-5 | Data Integration | Create SQL Tables | Task Done | Medium | Nova | 2022-07-04T11:56:21.925 0000 | Nova | Table tickets contain The fields of Jira Ticket (like Ticket number ,Summary , Description , Sprint ,Status ,�.)

Table Ticket_History : This table contain Ticket number, user ,Date & time , Field name ,Original Value , new value  |
DI-4 | Data Integration | Create Script python | Task In Progress | Medium | Nova | 2022-07-04T11:52:57.416 0000 | Nova | * Find the API that helps you to collect and extract the data from Jira 
* Insert the collected data in SQL data base  |
DI-2 | Data Integration | Install Environnement  | Task Done | Medium | Nova | 2022-07-04T11:49:08.332 0000 | Nova | Install Environnement |
DI-1 | Data Integration | Jira Data Integration Into SQL Data Base | Epic To Do | Medium | Nova | 2022-07-04T11:47:46.636 0000 | Nova | Jira Data Integration Into SQL Data Base |

After using this :

lista = []
for issue in jira.search_issues(jql_str=project):
   lista.append([issue.key, issue.fields.project.name, issue.fields.summary ...])

Here is the output:

[['DI-6', 'Data Integration', 'Create Jenkins Job to automatise the collect of data ', <JIRA IssueType: name='Task', id='10002'>, <JIRA Status: name='To Do', id='10000'>, <JIRA Priority: name='Medium', id='3'>, 'Nova', '2022-07-04T12:10:03.155 0000', <JIRA User: displayName='Nova', accountId='62c1b708ce5a604dbfb34700'>, 'Create Jenkins Job to automatise the collect of data daily'], ['DI-5', 'Data Integration', 'Create SQL Tables', <JIRA IssueType: name='Task', id='10002'>, <JIRA Status: name='Done', id='10002'>, <JIRA Priority: name='Medium', id='3'>, 'Nova', '2022-07-04T11:56:21.925 0000', <JIRA User: displayName='Nova', accountId='62c1b708ce5a604dbfb34700'>, 'Table tickets contain The fields of Jira Ticket (like Ticket number ,Summary , Description , Sprint ,Status ,�.)\n\nTable Ticket_History : This table contain Ticket number, user ,Date & time , Field name ,Original Value , new value '], ['DI-4', 'Data Integration', 'Create Script python', <JIRA IssueType: name='Task', id='10002'>, <JIRA Status: name='In Progress', id='10001'>, <JIRA Priority: name='Medium', id='3'>, 'Nova', '2022-07-04T11:52:57.416 0000', <JIRA User: displayName='Nova', accountId='62c1b708ce5a604dbfb34700'>, '* Find the API that helps you to collect and extract the data from Jira \n* Insert the collected data in SQL data base '], ['DI-2', 'Data Integration', 'Install Environnement ', <JIRA IssueType: name='Task', id='10002'>, <JIRA Status: name='Done', id='10002'>, <JIRA Priority: name='Medium', id='3'>, 'Nova', '2022-07-04T11:49:08.332 0000', <JIRA User: displayName='Nova', accountId='62c1b708ce5a604dbfb34700'>, 'Install Environnement'], ['DI-1', 'Data Integration', 'Jira Data Integration Into SQL Data Base', <JIRA IssueType: name='Epic', id='10004'>, <JIRA Status: name='To Do', id='10000'>, <JIRA Priority: name='Medium', id='3'>, 'Nova', '2022-07-04T11:47:46.636 0000', <JIRA User: displayName='Nova', accountId='62c1b708ce5a604dbfb34700'>, 'Jira Data Integration Into SQL Data Base']]

Why it adds <Jira and name="" and Id="" ... ? Idk :(

CodePudding user response:

After hours and hours.. I found out the all I had to do is adding .name after issues fields, like that:

issue.fields.summary,
issue.fields.issuetype.name,
issue.fields.status.name,
issue.fields.priority.name,
issue.fields.reporter.displayName,
issue.fields.created,
issue.fields.assignee.displayName,                                     

Thanks for your efforts for trying to help.

  • Related