Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Automating HR Notifications | Reporting and Insights for HR
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Python for HR Specialists

bookAutomating HR Notifications

HR notifications are essential tools for keeping employees informed and engaged. Automated notifications help HR teams ensure that important milestones, such as work anniversaries or contract renewals, are not overlooked. By sending timely reminders and acknowledgments, you can boost employee morale, reinforce a culture of recognition, and maintain compliance with organizational policies. Automating these notifications saves time, reduces manual errors, and allows HR professionals to focus on more strategic tasks.

1234567891011121314151617181920212223242526272829
import pandas as pd from datetime import datetime, timedelta # Sample employee data data = { "employee_id": [1, 2, 3, 4], "name": ["Alice Smith", "Bob Johnson", "Carol Lee", "David Kim"], "start_date": ["2020-07-15", "2019-08-10", "2021-06-01", "2018-07-30"] } df = pd.DataFrame(data) df["start_date"] = pd.to_datetime(df["start_date"]) today = datetime.today() upcoming_days = 7 def check_anniversaries(df, days_ahead): notifications = [] for _, row in df.iterrows(): anniversary_this_year = row["start_date"].replace(year=today.year) days_until = (anniversary_this_year - today).days if 0 <= days_until <= days_ahead: message = f"Reminder: {row['name']}'s work anniversary is on {anniversary_this_year.strftime('%Y-%m-%d')}!" notifications.append(message) return notifications anniversary_notifications = check_anniversaries(df, upcoming_days) for note in anniversary_notifications: print(note)
copy

To automate notifications based on HR events, you need to compare dates and format messages clearly. In the previous code, each employee's start_date is adjusted to the current year to find their next work anniversary. By subtracting today's date from this anniversary date, you get the number of days until the event. If this number falls within a specified range, such as the next week, a notification message is generated. Message formatting uses string interpolation to include employee names and dates, ensuring each notification is clear and personalized. These techniques allow you to automate reminders for any date-based HR event.

12345678910111213141516171819202122232425
# Example: Notify about contract renewals within the next month data = { "employee_id": [1, 2, 3, 4], "name": ["Alice Smith", "Bob Johnson", "Carol Lee", "David Kim"], "contract_end": ["2024-08-10", "2024-07-20", "2024-09-01", "2024-07-28"] } df_contracts = pd.DataFrame(data) df_contracts["contract_end"] = pd.to_datetime(df_contracts["contract_end"]) today = datetime.today() next_month = today + timedelta(days=30) def upcoming_contract_renewals(df, end_date): renewals = [] for _, row in df.iterrows(): if today <= row["contract_end"] <= end_date: message = f"Alert: {row['name']}'s contract ends on {row['contract_end'].strftime('%Y-%m-%d')}." renewals.append(message) return renewals contract_renewal_alerts = upcoming_contract_renewals(df_contracts, next_month) for alert in contract_renewal_alerts: print(alert)
copy

1. Why are automated notifications valuable in HR?

2. What type of HR events can be tracked for notifications?

3. Fill in the blank: To check if a date is within a range, use the _______ operator.

question mark

Why are automated notifications valuable in HR?

Select the correct answer

question mark

What type of HR events can be tracked for notifications?

Select the correct answer

question-icon

Fill in the blank: To check if a date is within a range, use the _______ operator.

inbetweenlogicalequality

Click or drag`n`drop items and fill in the blanks

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 3. Chapitre 6

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

bookAutomating HR Notifications

Glissez pour afficher le menu

HR notifications are essential tools for keeping employees informed and engaged. Automated notifications help HR teams ensure that important milestones, such as work anniversaries or contract renewals, are not overlooked. By sending timely reminders and acknowledgments, you can boost employee morale, reinforce a culture of recognition, and maintain compliance with organizational policies. Automating these notifications saves time, reduces manual errors, and allows HR professionals to focus on more strategic tasks.

1234567891011121314151617181920212223242526272829
import pandas as pd from datetime import datetime, timedelta # Sample employee data data = { "employee_id": [1, 2, 3, 4], "name": ["Alice Smith", "Bob Johnson", "Carol Lee", "David Kim"], "start_date": ["2020-07-15", "2019-08-10", "2021-06-01", "2018-07-30"] } df = pd.DataFrame(data) df["start_date"] = pd.to_datetime(df["start_date"]) today = datetime.today() upcoming_days = 7 def check_anniversaries(df, days_ahead): notifications = [] for _, row in df.iterrows(): anniversary_this_year = row["start_date"].replace(year=today.year) days_until = (anniversary_this_year - today).days if 0 <= days_until <= days_ahead: message = f"Reminder: {row['name']}'s work anniversary is on {anniversary_this_year.strftime('%Y-%m-%d')}!" notifications.append(message) return notifications anniversary_notifications = check_anniversaries(df, upcoming_days) for note in anniversary_notifications: print(note)
copy

To automate notifications based on HR events, you need to compare dates and format messages clearly. In the previous code, each employee's start_date is adjusted to the current year to find their next work anniversary. By subtracting today's date from this anniversary date, you get the number of days until the event. If this number falls within a specified range, such as the next week, a notification message is generated. Message formatting uses string interpolation to include employee names and dates, ensuring each notification is clear and personalized. These techniques allow you to automate reminders for any date-based HR event.

12345678910111213141516171819202122232425
# Example: Notify about contract renewals within the next month data = { "employee_id": [1, 2, 3, 4], "name": ["Alice Smith", "Bob Johnson", "Carol Lee", "David Kim"], "contract_end": ["2024-08-10", "2024-07-20", "2024-09-01", "2024-07-28"] } df_contracts = pd.DataFrame(data) df_contracts["contract_end"] = pd.to_datetime(df_contracts["contract_end"]) today = datetime.today() next_month = today + timedelta(days=30) def upcoming_contract_renewals(df, end_date): renewals = [] for _, row in df.iterrows(): if today <= row["contract_end"] <= end_date: message = f"Alert: {row['name']}'s contract ends on {row['contract_end'].strftime('%Y-%m-%d')}." renewals.append(message) return renewals contract_renewal_alerts = upcoming_contract_renewals(df_contracts, next_month) for alert in contract_renewal_alerts: print(alert)
copy

1. Why are automated notifications valuable in HR?

2. What type of HR events can be tracked for notifications?

3. Fill in the blank: To check if a date is within a range, use the _______ operator.

question mark

Why are automated notifications valuable in HR?

Select the correct answer

question mark

What type of HR events can be tracked for notifications?

Select the correct answer

question-icon

Fill in the blank: To check if a date is within a range, use the _______ operator.

inbetweenlogicalequality

Click or drag`n`drop items and fill in the blanks

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 3. Chapitre 6
some-alt