Company productivity dashboard π
employee_engagement = df_activities.groupby('employee_id').size()\
.reset_index(name='activity_count')\
.merge(df_employees[['employee_id', 'name', 'team']], on='employee_id')\
.sort_values('activity_count', ascending=False)
Run to view results
team_composition = df_employees.groupby(['team', 'role']).size().unstack()
Run to view results
def get_team_insights(team_name: str, df_employees: pd.DataFrame = df_employees,
df_activities: pd.DataFrame = df_activities) -> dict:
"""Generate comprehensive insights for a specific team.
:param team_name: str, name of the team for which to generate insights.
:param df_employees: pd.DataFrame, DataFrame containing employee data.
:param df_activities: pd.DataFrame, DataFrame containing activity data.
:return: dict, dictionary containing team insights.
"""
team_members = df_employees[df_employees['team'] == team_name]
team_activities = df_activities.merge(
df_employees[df_employees['team'] == team_name][['employee_id', 'name', 'role']],
on='employee_id'
)
team_size = len(team_members)
insights = {
'basic_stats': {
'team_size': team_size,
'total_activities': len(team_activities),
'avg_activities_per_person': round(len(team_activities) / team_size, 2) if team_size > 0 else 0,
'avg_productivity': round(team_activities['productivity_score'].mean(), 2) if team_size > 0 else 0
},
'team_composition': team_members.groupby('role').size().to_dict(),
'activity_breakdown': team_activities['activity_type'].value_counts().to_dict(),
'top_performers': team_activities.groupby('name')['productivity_score'].mean().nlargest(3).to_dict(),
'most_active_members': team_activities.groupby('name').size().nlargest(3).to_dict(),
'recent_activities': team_activities.sort_values('date', ascending=False).head(5)[
['date', 'name', 'activity_type', 'productivity_score']
].to_dict('records')
}
return insights
Run to view results
Run to view results
Team insights
Select team name
Run to view results
Team members insights
Select team member
if member_stats:
employee_id = df_employees[df_employees['name'] == person]['employee_id'].iloc[0]
df_employees['join_date'] = pd.to_datetime(df_employees['join_date'])
if df_activities['date'].dtype == 'O': # Check if the type is object, which means it might not be a datetime
df_activities['date'] = pd.to_datetime(df_activities['date'])
insights = get_employee_insights(employee_id, df_employees, df_activities)
employee_viz = visualize_employee_insights(employee_id, df_employees, df_activities)
employee_viz.show()
Run to view results
def compare_with_team(employee_id, df_employees, df_activities):
"""
Compare employee metrics with their team averages.
"""
employee = df_employees[df_employees['employee_id'] == employee_id].iloc[0]
team = employee['team']
employee_activities = df_activities[df_activities['employee_id'] == employee_id]
employee_metrics = {
'productivity': employee_activities['productivity_score'].mean(),
'duration': employee_activities['duration_hours'].mean(),
'activity_count': len(employee_activities)
}
team_members = df_employees[df_employees['team'] == team]['employee_id'].tolist()
team_members.remove(employee_id)
team_activities = df_activities[df_activities['employee_id'].isin(team_members)]
team_metrics = {
'productivity': team_activities['productivity_score'].mean(),
'duration': team_activities['duration_hours'].mean(),
'activity_count': len(team_activities) / len(team_members)
}
fig = go.Figure()
metrics = ['productivity', 'duration', 'activity_count']
employee_values = [employee_metrics[m] for m in metrics]
team_values = [team_metrics[m] for m in metrics]
fig.add_trace(go.Bar(
name='Employee',
x=metrics,
y=employee_values,
marker_color='rgb(26, 118, 255)'
))
fig.add_trace(go.Bar(
name='Team Average',
x=metrics,
y=team_values,
marker_color='rgb(158, 158, 158)'
))
fig.update_layout(
title=f"{employee['name']} vs {team} team average",
barmode='group',
height=400
)
return fig
Run to view results
Performance comparison
Run to view results
Run to view results