0

Good morning, first thank you for reading my question. When I am trying to create a pivot table using the Jira plugin, it appears that my columns are not being grouped together to allow pivot to aggregate the results.

Here is the code:

import sys
from jira.client import JIRA
import datetime
import pandas as pd

USER = 'USERNAME'
PW = 'PASSWORD'

today = datetime.date.today()
u = datetime.datetime.strptime(today.strftime('%m/%d/%y'),"%m/%d/%y").date()
twoweeks = datetime.timedelta(days=28)
total = u - twoweeks

print total

options = {'server': 'http://jira.com'}

jira = JIRA(options, basic_auth=(USER, PW))

ges_resolve = jira.search_issues('project=PROJECTNAME and resolutiondate >='+str(total), maxResults=-1)
ges_issue_id = []
for i in ges_resolve:
    print i
    ges_issue_id.append(i)

print ges_issue_id

#print ges_resolve

item_type = []

for val in ges_issue_id:
    issue = val
    print issue.fields.project
    project = issue.fields.project
    item_type.append((issue,issue.fields.issuetype))

print item_type
matrix = pd.DataFrame.from_records(item_type,columns=['CaseNumber','IssueType'])
print matrix

ges_jira_pivot_tab = matrix.pivot_table(rows='CaseNumber',cols='IssueType',aggfunc=len,fill_value=0)
print ges_jira_pivot_tab

total_res = len(ges_resolve)
print total_res

Based on the image I supplied, the dataframe I constructed is as I expected, but when I convert that data to a pivot table, it doesn't aggregate the columns together.

Any help is apprecaited.

Here is the image of the datafram and the start of the pivot table:

enter image description here

Thank you for the response below, one additional point of data to add. Before I convert the list that contains the jira data in to a data frame, this is what it looks like when I print the list.

enter image description here

It appears that the casenumber is a nested dictionary inside a tuple(Is that correct?). Everytime I try to unpack the dictionary from the tuple, I get an error. If I am missing something obvious, please forgive me as I am still relatively new to python.

Thanks again for any help.

Chris
  • 569
  • 2
  • 8
  • 15

1 Answers1

0

I'd check the exact format that the pd library expects the data to be in, and then create a pivot table with some dummy data, then make sure the objects from JIRA match the same data type

mdoar
  • 6,758
  • 1
  • 21
  • 20