Automating 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.
1234567891011121314151617181920212223242526272829import 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)
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)
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.
¡Gracias por tus comentarios!
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla
Genial!
Completion tasa mejorada a 4.76
Automating HR Notifications
Desliza para mostrar el menú
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.
1234567891011121314151617181920212223242526272829import 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)
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)
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.
¡Gracias por tus comentarios!