Pandas Excel: Find a list of employees of a specified year
18. Filter Employees of a Specified Year
Write a Pandas program to import given excel data (employee.xlsx ) into a Pandas dataframe and find a list of employees of a specified year. Go to Excel data
Sample Solution:
Python Code :
import pandas as pd
import numpy as np
df = pd.read_excel('E:\employee.xlsx')
df2 = df.set_index(['hire_date'])
result = df2["2005"]
result
Sample Output:
hire_date 2005-09-21 101 Neena Kochhar 2005-06-25 105 David Austin 2005-09-28 110 John Chen 2005-09-30 111 Ismael Sciarra 2005-12-24 116 Shelli Baida 2005-07-24 117 Sigal Tobias
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 in a specific year.
- Write a Pandas program to extract employee records where the hire_date falls within a given year and display the result.
- Write a Pandas program to use the year attribute of the hire_date column to filter employees by a specified year.
- Write a Pandas program to group employee records by hire year and then select a particular year’s data.
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Pandas program to import given excel data (employee.xlsx ) into a Pandas dataframe and find a list of employees where hire_date between two specific month and year.
Next: Write a Pandas program to import given excel data (employee.xlsx ) into a Pandas dataframe and convert the data to use the hire_date as the index.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.