Pandas Excel: Find a list of employees of a specified year
Pandas: Excel Exercise-18 with Solution
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
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.
Python: Tips of the Day
Split a String:
>>> sentence = 'this is, a python, tutorial, about, idioms.' >>> sentence.split(', ') ['this is', 'a python', 'tutorial', 'about', 'idioms.'] >>> sentence.split(', ', 2) ['this is', 'a python', 'tutorial, about, idioms.'] >>> sentence.rsplit(', ') ['this is', 'a python', 'tutorial', 'about', 'idioms.'] >>> sentence.rsplit(', ', 2) ['this is, a python, tutorial', 'about', 'idioms.']
- Exercises: Weekly Top 12 Most Popular Topics
- Pandas DataFrame: Exercises, Practice, Solution
- Conversion Tools
- JavaScript: HTML Form Validation
- SQL Exercises, Practice, Solution - SUBQUERIES
- C Programming Exercises, Practice, Solution : For Loop
- Python Exercises, Practice, Solution
- Python Data Type: List - Exercises, Practice, Solution
- C++ Basic: Exercises, Practice, Solution
- SQL Exercises, Practice, Solution - exercises on Employee Database
- SQL Exercises, Practice, Solution - exercises on Movie Database
- SQL Exercises, Practice, Solution - exercises on Soccer Database
- C Programming Exercises, Practice, Solution : Recursion