Pandas Excel: Import sheet2 data from a given excel sheet data into a Pandas dataframe
21. Import Sheet2 Data
Write a Pandas program to import sheet2 data from a given excel data (employee.xlsx ) into a Pandas dataframe. Go to Excel data
Sample Solution:
Python Code :
import pandas as pd
import numpy as np
df = pd.read_excel('E:\employee.xlsx',sheet_name=1)
print(df)
Sample Output:
emp_id first_name last_name hire_date 0 120 Matthew Weiss 2004-07-18 1 121 Adam Fripp 2005-04-10 2 122 Payam Kaufling 2003-05-01 3 123 Shanta Vollman 2005-10-10 4 124 Kevin Mourgos 2007-11-16 5 125 Julia Nayer 2005-07-16 6 126 Irene Mikkilineni 2006-09-28 7 127 James Landry 2007-01-14 8 128 Steven Markle 2008-03-08 9 129 Laura Bissot 2005-08-20 10 130 Mozhe Atkinson 2005-10-30 11 131 James Marlow 2005-02-16 12 132 TJ Olson 2007-04-10 13 133 Jason Mallin 2004-06-14 14 134 Michael Rogers 2006-08-26 15 135 Ki Gee 2007-12-12 16 136 Hazel Philtanker 2008-02-06 17 137 Renske Ladwig 2003-07-14 18 138 Stephen Stiles 2005-10-26
Excel Data:
employee.xlsx:
Sheet-1
Sheet-2
Sheet-3
For more Practice: Solve these Related Problems:
- Write a Pandas program to import the second sheet (Sheet2) from employee.xlsx into a DataFrame and display its summary.
- Write a Pandas program to load Sheet2 of an Excel file and then print the first few rows.
- Write a Pandas program to read a specific sheet from an Excel file and verify its columns.
- Write a Pandas program to import Sheet2 data and then compare its structure with that of Sheet1 from the same file.
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 sort based on multiple given columns.
Next: Write a Pandas program to import three datasheets from a given excel data (coalpublic2013.xlsx ) into a single dataframe.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.