After searching, I found a few things out but now im stumped. In the worksheet it is a table with multiple incidents and I'm trying to get all closed and rejected incidents:
EDITED
def allIncidents(df):
# creates a list of all Incidents
pivot = pd.pivot_table(df, index=["Queue"], values=["Status"], aggfunc='count').reset_index()
ws = wb.active
ws.title = 'All Incidents'
pivot_length = pivot.shape
len = pivot_length[0]
i = 0
while i < len:
ws.cell(row=i + 1, column=1).value = pivot.values[i][0]
ws.cell(row=i + 1, column=2).value = pivot.values[i][1]
i = i + 1
pie = PieChart()
labels = Reference(ws, min_col=1, min_row=1, max_col=1, max_row=len)
data_val = Reference(ws, min_col=2, min_row=1, max_col=2, max_row=len)
pie.add_data(data_val, titles_from_data=True)
pie.set_categories(labels)
pie.title = "Incidents per Queue"
# Use this to post on Graph sheet
graphSheet.add_chart(pie, "B6")
def allClosedIncidents(df):
# creates a list of all closed Incidents
df = df.loc[(df['Status'] == 'CLOSED') & (df['Status'] == 'REJECTED')]
# df = df.loc[(df['Status'].isin('CLOSED')) & (df['Status'].isin('CLOSED'))]
pivot = pd.pivot_table(df, index=["Queue"], values=["Status"], aggfunc='count').reset_index()
ws = wb.active
ws.title = 'All Closed Incidents'
pivot_length = pivot.shape
len = pivot_length[0]
i = 0
while i < len:
ws.cell(row=i + 1, column=1).value = pivot.values[i][0]
ws.cell(row=i + 1, column=2).value = pivot.values[i][1]
i = i + 1
pie = PieChart()
labels = Reference(ws, min_col=1, min_row=1, max_col=1, max_row=len)
data_val = Reference(ws, min_col=2, min_row=1, max_col=2, max_row=len)
pie.add_data(data_val, titles_from_data=True)
pie.set_categories(labels)
pie.title = "Closed Incidents per Queue"
# Use this to post on Graph sheet
graphSheet.add_chart(pie, "I6")
Error code
Traceback (most recent call last):
File "C:/Users/THABISO/PycharmProjects/Bancabc/BANCABC.py", line 276, in <module>
allClosedIncidents()
File "C:/Users/THABISO/PycharmProjects/Bancabc/BANCABC.py", line 79, in allClosedIncidents
labels = Reference(ws, min_col=1, min_row=1, max_col=1, max_row=len)
File "C:\Users\THABISO\venv\lib\site-packages\openpyxl\chart\reference.py", line 60, in __init__
self.max_row = max_row
File "C:\Users\THABISO\venv\lib\site-packages\openpyxl\descriptors\base.py", line 107, in __set__
raise ValueError('Min value is {0}'.format(self.min))
ValueError: Min value is 1
The code is breaking at:
pivot = pd.pivot_table(df, index=["Queue"], values=["Status"], aggfunc='count').reset_index()
The value of len in the first method is: 5
len in the second is: 0 (even though there are 100 closed and 20 rejected records
column names are: Queue,Client ID,Branch/Department,Category,Incident: Number,Staff,Description,Resolution,Opened Date,Due Date,Closed Date,Status,Compliant