Title: Load Excel Spreadsheet As Pandas Dataframe
Slug: pandas_dataframe_load_xls
Summary: Load Excel Spreadsheet As Pandas Dataframe
Date: 2016-05-01 12:00
Category: Python
Tags: Data Wrangling
Authors: Chris Albon


In [9]:
# import modules
import pandas as pd

In [10]:
# Import the excel file and call it xls_file
xls_file = pd.ExcelFile('../data/example.xls')
xls_file


Out[10]:
<pandas.io.excel.ExcelFile at 0x111912be0>

In [11]:
# View the excel file's sheet names
xls_file.sheet_names


Out[11]:
['Sheet1']

In [12]:
# Load the xls file's Sheet1 as a dataframe
df = xls_file.parse('Sheet1')
df


Out[12]:
year deaths_attacker deaths_defender soldiers_attacker soldiers_defender wounded_attacker wounded_defender
0 1945 425 423 2532 37235 41 14
1 1956 242 264 6346 2523 214 1424
2 1964 323 1231 3341 2133 131 131
3 1969 223 23 6732 1245 12 12
4 1971 783 23 12563 2671 123 34
5 1981 436 42 2356 7832 124 124
6 1982 324 124 253 2622 264 1124
7 1992 3321 631 5277 3331 311 1431
8 1999 262 232 2732 2522 132 122
9 2004 843 213 6278 26773 623 2563