I am working on a KPI. I have a data frame which has two columns with different date time. I want to find the difference in time and group by its service and find the average time taken for each service. Then i want to display the service and average time in dash table. when i am printing in my IDE i am getting correct format(eg. 4 days 6:2:10.34 ), but when i showing in dash data table i am getting this format P4DT6H2M. I want to display as 4days 6 hours 2 minutes. Please somebody help. Thank in advance.
df['Total_Time'] = pd.to_datetime(df['SolutionTime']) - pd.to_datetime(df['Created'])
avg= df.groupby('Service')[['Total_Time']].mean().reset_index().rename({'Total_Time':'Average'}, axis=1) # Average time for each service
app = dash.Dash(__name__, meta_tags=[{"name": "viewport", "content": "width=device-width"}])
app.layout = html.Div([
html.Div([
html.Div([
dt.DataTable(id='data_table',
columns=[{'name': i, 'id': i} for i in avg]
],className='row flex-display')
], id='mainContainer', style={'display': 'flex', 'flex-direction': 'column'})
@app.callback(Output('data_table','data'),
[Input('month_selection','value')])
def update_table(month_selection):
return avg.to_dict('records')
if __name__ == '__main__':
app.run_server(debug=True)