The solution and the test-array contains an error. It misses leap years. It is also easy to see that the last element in the test array (i.e., “Hale Cole,“Atlanta, GA”,2000-10-24,2021-10-20,”$54,500",engineering"), which according to the test array is supposed to be equal to 21. It should be 20
It seems that this problem is relatively hard to solve correctly. But the following should do the job but is unfortunately bulky.
staff["age"] = staff["start_date"].dt.year - staff["date_of_birth"].dt.year - ((staff["start_date"].dt.month - staff["date_of_birth"].dt.month < 0) | ((staff["start_date"].dt.month - staff["date_of_birth"].dt.month == 0) & (staff["start_date"].dt.day - staff["date_of_birth"].dt.day < 0))) * 1
Course: Mastering Data Analysis with Python Pandas - Learn Interactively
Lesson: Challenge: The Age of Employees - Mastering Data Analysis with Python Pandas
Course: Mastering Data Analysis with Python Pandas - Learn Interactively
Lesson: Challenge: The Age of Employees - Mastering Data Analysis with Python Pandas