msl.io.tables module

Read a data table from a file.

msl.io.tables.extension_delimiter_map = {'.csv': ','}

The delimiter to use to separate columns in a table based on the file extension.

If the delimiter is not specified when calling the read_table() function then this extension-delimiter map is used to determine the value of the delimiter. If the file extension is not in the map then the value of the delimiter is None (i.e., split columns by any whitespace).

Examples

You can customize your own map by adding key-value pairs

>>> from msl.io import extension_delimiter_map
>>> extension_delimiter_map['.txt'] = '\t'
Type:

dict

msl.io.tables.read_table_excel(file, cells=None, sheet=None, as_datetime=True, dtype=None, **kwargs)[source]

Read a data table from an Excel spreadsheet.

A table has the following properties:

  1. The first row is a header.

  2. All rows have the same number of columns.

  3. All data values in a column have the same data type.

Parameters:
  • file (path-like or file-like) – The file to read.

  • cells (str, optional) – The cells to read. For example, C9 will start at cell C9 and include all values until the end of the spreadsheet, A:C includes all rows in columns A, B and C, and, C9:G20 includes values from only the specified cells. If not specified then returns all values from the specified sheet.

  • sheet (str, optional) – The name of the sheet to read the data from. If there is only one sheet in the workbook then you do not need to specify the name of the sheet.

  • as_datetime (bool, optional) – Whether dates should be returned as datetime or date objects. If False then dates are returned as a str.

  • dtype (object, optional) – If specified then it must be able to be converted to a dtype object.

  • **kwargs – All additional keyword arguments are passed to open_workbook(). Can use an encoding keyword argument as an alias for encoding_override.

Returns:

Dataset – The table as a Dataset. The header is included in the Metadata.

msl.io.tables.read_table_gsheets(file, cells=None, sheet=None, as_datetime=True, dtype=None, **kwargs)[source]

Read a data table from a Google Sheets spreadsheet.

Attention

You must have already performed the instructions specified in GDrive and in GSheets to be able to use this function.

A table has the following properties:

  1. The first row is a header.

  2. All rows have the same number of columns.

  3. All data values in a column have the same data type.

Parameters:
  • file (path-like or file-like) – The file to read. Can be the ID of a Google Sheets spreadsheet.

  • cells (str, optional) – The cells to read. For example, C9 will start at cell C9 and include all values until the end of the spreadsheet, A:C includes all rows in columns A, B and C, and, C9:G20 includes values from only the specified cells. If not specified then returns all values from the specified sheet.

  • sheet (str, optional) – The name of the sheet to read the data from. If there is only one sheet in the spreadsheet then you do not need to specify the name of the sheet.

  • as_datetime (bool, optional) – Whether dates should be returned as datetime or date objects. If False then dates are returned as a str.

  • dtype (object, optional) – If specified then it must be able to be converted to a dtype object.

  • **kwargs – All additional keyword arguments are passed to GSheetsReader.

Returns:

Dataset – The table as a Dataset. The header is included in the Metadata.

msl.io.tables.read_table_text(file, **kwargs)[source]

Read a data table from a text-based file.

A table has the following properties:

  1. The first row is a header.

  2. All rows have the same number of columns.

  3. All data values in a column have the same data type.

Parameters:
  • file (path-like or file-like) – The file to read.

  • **kwargs – All keyword arguments are passed to loadtxt(). If the delimiter is not specified and the file has csv as the file extension then the delimiter is automatically set to be ','.

Returns:

Dataset – The table as a Dataset. The header is included in the Metadata.