v Load Excel Spreadsheet As Pandas Dataframe - Python

Load Excel Spreadsheet As Pandas Dataframe

# import modules
import pandas as pd
# Import the excel file and call it xls_file
xls_file = pd.ExcelFile('../data/example.xls')
xls_file
<pandas.io.excel.ExcelFile at 0x111912be0>
# View the excel file's sheet names
xls_file.sheet_names
['Sheet1']
# Load the xls file's Sheet1 as a dataframe
df = xls_file.parse('Sheet1')
df
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