Я обновил сводную таблицу, добавив Owned By Group. Когда я смотрю на df, данные находятся в формате, который я ожидаю. Когда я передаю df функции SLA_Chart, она взрывается,
def PrepareDataSLAChart(df):
# Change Datatypes
df['Date'] = pd.to_datetime(df['Date'])
df = df.drop(['CreatedDate','Incident_ID'], axis='columns')
df['Sum']df.groupby(['Owned_By_Team',pd.Grouper(key='Date',freq='M'),
'Incident_Type'])['SLA_Resolution_Good'].transform(sum)
df['Count']df.groupby(['Owned_By_Team',pd.Grouper(key='Date',freq='M')
,'Incident_Type'])['Sum'].transform('count')
df['Percent_of_SLA'] = round((df["Sum"] / df["Count"] * 100),2)
# No longer need SLA Field
df = df.drop(['SLA_Resolution_Good','Count','Sum'], axis='columns')
df.index = df['Date']
df['Date'] = pd.to_datetime(df['Date']) - MonthBegin(1)
df = pd.pivot_table(df,index=['Owned_By_Team',
(pd.Grouper(key='Date',freq='M'))],columns='Incident_Type',
values='Percent_of_SLA')
return df
def SLA_Chart(df):
output_file("multiline_plot.html")
source = ColumnDataSource(df)
TOOLS = 'crosshair,save,pan,box_zoom,reset,wheel_zoom'
p = figure(
plot_width = 1600,
plot_height = 800,
y_axis_type = "linear",
x_axis_type = 'datetime', tools = TOOLS
)
# configure visual properties on a plot's title attribute
p.title.text = 'Team Patriots'
p.title.align = "center"
p.title.text_color = "black"
p.title.text_font_size = "25px"
p.line('Date','Incident',source=source,
legend='Incidents',
line_color="blue",
line_width = 3,
line_cap = 'round')
p.circle('Date','Incident',source=source,
line_color='blue',
line_width = 3)
p.line("Date", "Service Request",source=source,
legend="Service Requests",
line_color="red",
line_width = 3,
line_cap = 'round')
p.circle('Date','Service Request',source=source,
line_color='red',
line_width = 3)
p.legend.location = "top_left"
p.xaxis.axis_label = 'Date'
p.yaxis.axis_label = '% Met'
# open a browser
return (show(p))