sciris.sc_fileio.loadspreadsheet

loadspreadsheet(filename=None, folder=None, fileobj=None, sheet=0, asdataframe=None, header=True, method='pandas', **kwargs)[source]

Load a spreadsheet as a dataframe or a list of lists.

By default, an alias to pandas.read_excel() with a header, but also supports loading via openpyxl or xlrd. Read from either a filename or a file object.

Parameters
  • filename (str) – filename or path to read

  • folder (str) – optional folder to use with the filename

  • fileobj (obj) – load from file object rather than path

  • sheet (str/int/list) – name or number of sheet(s) to use (default 0)

  • asdataframe (bool) – whether to return as a pandas/Sciris dataframe (default True)

  • method (str) – how to read (default ‘pandas’, other choices ‘openpyxl’ and ‘xlrd’)

  • kwargs (dict) – passed to pd.read_excel(), openpyxl(), etc.

Examples:

df = sc.loadspreadsheet('myfile.xlsx') # Alias to pd.read_excel(header=1)
wb = sc.loadspreadsheet('myfile.xlsx', method='openpyxl') # Returns workbook
data = sc.loadspreadsheet('myfile.xlsx', method='xlrd', asdataframe=False) # Returns raw data; requires xlrd

New in version 1.3.0: change default from xlrd to pandas; renamed sheetname and sheetnum arguments to sheet.