Pandas Excel: Find a list of employees where hire_date is greater than specific date
15. Filter Employees by Hire Date (> 01-01-07)
Write a Pandas program to import given excel data (employee.xlsx ) into a Pandas dataframe and find a list of employees where hire_date> 01-01-07. Go to Excel data
Sample Solution:
Python Code :
import pandas as pd
import numpy as np
df = pd.read_excel('E:\employee.xlsx')
df[df['hire_date'] >='20070101']
Sample Output:
emp_id first_name last_name hire_date 4 104 Bruce Ernst 2007-05-21 7 107 Diana Lorentz 2007-02-07 13 113 Luis Popp 2007-12-07 19 119 Karen Colmenares 2007-08-10
Excel Data:
employee.xlsx:
Sheet-1
Sheet-2
Sheet-3
For more Practice: Solve these Related Problems:
- Write a Pandas program to import employee.xlsx and filter the DataFrame for employees hired after January 1, 2007.
- Write a Pandas program to select employee records with a hire_date greater than 01-01-07 and display their details.
- Write a Pandas program to use a datetime filter on employee.xlsx data to extract employees hired after a specific date.
- Write a Pandas program to convert the hire_date column to datetime and then filter employees based on the hire_date condition.
Go to:
Previous: Write a Pandas program to import given excel data (coalpublic2013.xls ) into a dataframe and find all records that include two specific MSHA ID.
Next: Write a Pandas program to import given excel data (employee.xlsx ) into a Pandas dataframe and to sort the records by the hire_date column.
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.