Skip to content

Instantly share code, notes, and snippets.

@rsperl
Last active January 31, 2023 15:10
Show Gist options
  • Save rsperl/9ec31b863fad46ace499a387e30a4333 to your computer and use it in GitHub Desktop.
Save rsperl/9ec31b863fad46ace499a387e30a4333 to your computer and use it in GitHub Desktop.
Reading excel files with python and panda #snippet
#!/usr/bin/env python
# src: http://pandas.pydata.org/pandas-docs/stable/io.html#io-excel-reader
import pandas as pd
# get a dataframe from xlsx object
xlsx = pd.ExcelFile('path_to_file.xls')
df = pd.read_excel(xlsx, 'Sheet1')
# get dataframe from context object
with pd.ExcelFile('path_to_file.xls') as xls:
df1 = pd.read_excel(xls, 'Sheet1')
df2 = pd.read_excel(xls, 'Sheet2')
# examples of manipulating dataframes
# http://code-love.com/2017/04/30/excel-sql-python/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment