{ "metadata": { "name": "", "signature": "sha256:05c821da00d3867ebbc48fe492a509d12d316826ad27403454f83c6a111a1695" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Load Excel Spreadsheet As Pandas Dataframe\n", "\n", "- **Author:** [Chris Albon](http://www.chrisalbon.com/), [@ChrisAlbon](https://twitter.com/chrisalbon)\n", "- **Date:** -\n", "- **Repo:** [Python 3 code snippets for data science](https://github.com/chrisalbon/code_py)\n", "- **Note:**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### import modules" ] }, { "cell_type": "code", "collapsed": false, "input": [ "import pandas as pd" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 8 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Import the excel file and call it xls_file" ] }, { "cell_type": "code", "collapsed": false, "input": [ "xls_file = pd.ExcelFile('/Users/chrisralbon/Dropbox (Personal)/Public/example.xls')\n", "xls_file" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 19, "text": [ "" ] } ], "prompt_number": 19 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### View the excel file's sheet names" ] }, { "cell_type": "code", "collapsed": false, "input": [ "xls_file.sheet_names" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 20, "text": [ "['Sheet1', 'Sheet2']" ] } ], "prompt_number": 20 }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Load the xls file's Sheet1 as a dataframe" ] }, { "cell_type": "code", "collapsed": false, "input": [ "df = xls_file.parse('Sheet1')\n", "df" ], "language": "python", "metadata": {}, "outputs": [ { "html": [ "
\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
FirstNameLastNameLocationAge
0 Jason Miller USA 43
1 Bill Macoi USA 25
2 Jane Modi UK 25
3 Sara Mosi UK 62
\n", "

4 rows \u00d7 4 columns

\n", "
" ], "metadata": {}, "output_type": "pyout", "prompt_number": 22, "text": [ " FirstName LastName Location Age\n", "0 Jason Miller USA 43\n", "1 Bill Macoi USA 25\n", "2 Jane Modi UK 25\n", "3 Sara Mosi UK 62\n", "\n", "[4 rows x 4 columns]" ] } ], "prompt_number": 22 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }