Python for HR Analytics Tutor
Specialized skill for HR analytics Python work. General teaching preferences (explain WHY, beginner-friendly, error handling, etc.) are defined in the global claude.md — this skill adds HR-specific context and patterns.
When to Load References
Load these files based on the task:
references/python-basics.md — For foundational Python concepts (data types, variables, DataFrames, basic operators, errors). Use when revisiting fundamentals.
references/hr-patterns.md — For specific HR analytics operations (turnover calculations, time-to-fill, cohort analysis, data merging, aggregations). Use for "how do I do X" questions.
references/complete-examples.md — For end-to-end workflows (comprehensive turnover analysis, recruiting funnel, retention cohorts, forecasting). Use for understanding full analytical processes.
Loading strategy:
- Basic concept questions →
python-basics.md
- Specific pandas/HR operations →
hr-patterns.md
- Complete workflow examples →
complete-examples.md
- Complex projects → may need multiple references
HR Analytics Domain Context
Common Metrics
- Turnover rate: (terminations / headcount) × 100 — voluntary, involuntary, by segment
- Time-to-fill: Days from req open to offer accept — by role, office, aged reqs
- Retention rate: Cohort-based (% still employed after X months) or milestone-based
- Headcount: Point-in-time counts, trending by month/segment
- Span of control: Direct reports per manager
Common Data Operations
- Merging employee data across systems (HRIS, ATS, payroll)
- Fuzzy name matching across sources
- Date range filtering (active during period, hired between dates)
- Aggregating by multiple dimensions (role + office + tenure band)
- Creating derived fields (tenure buckets, age bands, performance tiers)
Analysis Types
- Cohort analysis: Retention by hire period
- Funnel analysis: Recruiting stages and conversion rates
- Trend analysis: Metrics over time
- Segment comparison: By role, office, tenure, performance
- Forecasting: Headcount projections, attrition predictions
HR-Specific Code Patterns
Turnover Rate by Segment
# Count terminations per segment
terms = df[df['is_terminated']].groupby('segment').size()
# Count total headcount per segment
headcount = df.groupby('segment').size()
# Calculate rate
turnover_rate = (terms / headcount * 100).round(2)
Time-to-Fill Calculation
# Convert dates and calculate days
df['req_open'] = pd.to_datetime(df['req_open'])
df['offer_accept'] = pd.to_datetime(df['offer_accept'])
df['time_to_fill'] = (df['offer_accept'] - df['req_open']).dt.days
# Average by role
ttf_by_role = df.groupby('role')['time_to_fill'].mean().round(1)
Tenure Calculation
# Calculate tenure in years (accounting for leap years)
df['tenure_years'] = (pd.Timestamp.now() - df['hire_date']).dt.days / 365.25
# Create tenure bands
df['tenure_band'] = pd.cut(
df['tenure_years'],
bins=[0, 1, 3, 5, 10, float('inf')],
labels=['<1 yr', '1-3 yrs', '3-5 yrs', '5-10 yrs', '10+ yrs']
)
Cohort Retention
# Create hire cohort (year-month)
df['hire_cohort'] = df['hire_date'].dt.to_period('M')
# Calculate months since hire
df['months_since_hire'] = (
(pd.Timestamp.now() - df['hire_date']).dt.days / 30.44
).astype(int)
# Retention at milestone
milestone = 12 # months
cohort_size = df.groupby('hire_cohort').size()
still_active = df[
(df['is_active']) & (df['months_since_hire'] >= milestone)
].groupby('hire_cohort').size()
retention_rate = (still_active / cohort_size * 100).round(1)
Recruiting Funnel
# Stage conversion rates
funnel = df.groupby('stage').size().reset_index(name='count')
funnel['conversion'] = (
funnel['count'] / funnel['count'].iloc[0] * 100
).round(1)
# Stage-to-stage drop-off
funnel['stage_conversion'] = (
funnel['count'] / funnel['count'].shift(1) * 100
).round(1)
Data Source Context
Typical data sources in this environment:
- BigQuery: Primary data warehouse
- Workday RaaS: HR system reports
- CSV/Excel exports: Ad-hoc data pulls
Common data quality issues to watch for:
- Multiple records per employee (need to deduplicate or filter to latest)
- Date fields as strings (need pd.to_datetime conversion)
- Inconsistent department/role naming across systems
- Missing termination dates for active employees (expected, not an error)
1---2name: python-hr-analytics-tutor3description: Specialized Python tutoring for HR analytics professionals. Use when working on HR/talent analytics tasks involving turnover, time-to-fill, retention, headcount, recruiting analytics, or other People Analytics metrics. Loads HR-specific patterns and examples.4---5
6# Python for HR Analytics Tutor
7
8Specialized skill for HR analytics Python work. General teaching preferences (explain WHY, beginner-friendly, error handling, etc.) are defined in the global `claude.md` — this skill adds HR-specific context and patterns.
9
10## When to Load References
11
12**Load these files based on the task:**
13
14- **`references/python-basics.md`** — For foundational Python concepts (data types, variables, DataFrames, basic operators, errors). Use when revisiting fundamentals.
15
16- **`references/hr-patterns.md`** — For specific HR analytics operations (turnover calculations, time-to-fill, cohort analysis, data merging, aggregations). Use for "how do I do X" questions.
17
18- **`references/complete-examples.md`** — For end-to-end workflows (comprehensive turnover analysis, recruiting funnel, retention cohorts, forecasting). Use for understanding full analytical processes.
19
20**Loading strategy:**
21- Basic concept questions → `python-basics.md`
22- Specific pandas/HR operations → `hr-patterns.md`
23- Complete workflow examples → `complete-examples.md`
24- Complex projects → may need multiple references
25
26## HR Analytics Domain Context
27
28### Common Metrics
29- **Turnover rate**: (terminations / headcount) × 100 — voluntary, involuntary, by segment
30- **Time-to-fill**: Days from req open to offer accept — by role, office, aged reqs
31- **Retention rate**: Cohort-based (% still employed after X months) or milestone-based
32- **Headcount**: Point-in-time counts, trending by month/segment
33- **Span of control**: Direct reports per manager
34
35### Common Data Operations
36- Merging employee data across systems (HRIS, ATS, payroll)
37- Fuzzy name matching across sources
38- Date range filtering (active during period, hired between dates)
39- Aggregating by multiple dimensions (role + office + tenure band)
40- Creating derived fields (tenure buckets, age bands, performance tiers)
41
42### Analysis Types
43- **Cohort analysis**: Retention by hire period
44- **Funnel analysis**: Recruiting stages and conversion rates
45- **Trend analysis**: Metrics over time
46- **Segment comparison**: By role, office, tenure, performance
47- **Forecasting**: Headcount projections, attrition predictions
48
49## HR-Specific Code Patterns
50
51### Turnover Rate by Segment
52```python
53# Count terminations per segment
54terms = df[df['is_terminated']].groupby('segment').size()
55
56# Count total headcount per segment
57headcount = df.groupby('segment').size()
58
59# Calculate rate
60turnover_rate = (terms / headcount * 100).round(2)
61```
62
63### Time-to-Fill Calculation
64```python
65# Convert dates and calculate days
66df['req_open'] = pd.to_datetime(df['req_open'])
67df['offer_accept'] = pd.to_datetime(df['offer_accept'])
68df['time_to_fill'] = (df['offer_accept'] - df['req_open']).dt.days
69
70# Average by role
71ttf_by_role = df.groupby('role')['time_to_fill'].mean().round(1)
72```
73
74### Tenure Calculation
75```python
76# Calculate tenure in years (accounting for leap years)
77df['tenure_years'] = (pd.Timestamp.now() - df['hire_date']).dt.days / 365.25
78
79# Create tenure bands
80df['tenure_band'] = pd.cut(
81 df['tenure_years'],
82 bins=[0, 1, 3, 5, 10, float('inf')],
83 labels=['<1 yr', '1-3 yrs', '3-5 yrs', '5-10 yrs', '10+ yrs']
84)
85```
86
87### Cohort Retention
88```python
89# Create hire cohort (year-month)
90df['hire_cohort'] = df['hire_date'].dt.to_period('M')
91
92# Calculate months since hire
93df['months_since_hire'] = (
94 (pd.Timestamp.now() - df['hire_date']).dt.days / 30.44
95).astype(int)
96
97# Retention at milestone
98milestone = 12 # months
99cohort_size = df.groupby('hire_cohort').size()
100still_active = df[
101 (df['is_active']) & (df['months_since_hire'] >= milestone)
102].groupby('hire_cohort').size()
103retention_rate = (still_active / cohort_size * 100).round(1)
104```
105
106### Recruiting Funnel
107```python
108# Stage conversion rates
109funnel = df.groupby('stage').size().reset_index(name='count')
110funnel['conversion'] = (
111 funnel['count'] / funnel['count'].iloc[0] * 100
112).round(1)
113
114# Stage-to-stage drop-off
115funnel['stage_conversion'] = (
116 funnel['count'] / funnel['count'].shift(1) * 100
117).round(1)
118```
119
120## Data Source Context
121
122Typical data sources in this environment:
123- **BigQuery**: Primary data warehouse
124- **Workday RaaS**: HR system reports
125- **CSV/Excel exports**: Ad-hoc data pulls
126
127Common data quality issues to watch for:
128- Multiple records per employee (need to deduplicate or filter to latest)
129- Date fields as strings (need pd.to_datetime conversion)
130- Inconsistent department/role naming across systems
131- Missing termination dates for active employees (expected, not an error)