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 isNone
(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:
- 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:
The first row is a header.
All rows have the same number of columns.
All data values in a column have the same data type.
- Parameters:
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 asdatetime
ordate
objects. IfFalse
then dates are returned as astr
.dtype (
object
, optional) – If specified then it must be able to be converted to adtype
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 aDataset
. The header is included in theMetadata
.
- 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 inGSheets
to be able to use this function.A table has the following properties:
The first row is a header.
All rows have the same number of columns.
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 asdatetime
ordate
objects. IfFalse
then dates are returned as astr
.dtype (
object
, optional) – If specified then it must be able to be converted to adtype
object.**kwargs – All additional keyword arguments are passed to
GSheetsReader
.
- Returns:
Dataset
– The table as aDataset
. The header is included in theMetadata
.
- msl.io.tables.read_table_text(file, **kwargs)[source]
Read a data table from a text-based file.
A table has the following properties:
The first row is a header.
All rows have the same number of columns.
All data values in a column have the same data type.