neuralib.tools.gspread.GoogleWorkSheet

class neuralib.tools.gspread.GoogleWorkSheet[source]

Bases: object

__init__(worksheet, primary_key='Data')[source]
Parameters:
  • worksheet (Worksheet) – gspread.Worksheet

  • primary_key (str | tuple[str, ...]) –

    Primary key of the worksheet.

    If str type, it must be one of the column name.

    If tuple str type, the primary key is join using “_” per row

Methods

__init__(worksheet[, primary_key])

clear()

Clears all cells in the worksheet

get_cell(data, head[, value_render_option])

Get data from a cell

get_range_value(a1_range_notation)

get values from range notation.

of(name, page, service_account_path[, ...])

Get a worksheet from spreadsheet

to_pandas()

Worksheet to pandas dataframe

to_polars()

Worksheet to polar dataframe

update(range_name[, values])

Sets values in a cell range of the sheet

update_cell(data, head, value)

Update value in a cell

values(head)

get list of value from header

Attributes

headers

list of worksheet header

primary_key_list

list of primary key of the worksheet

title

WorkPageName

__init__(worksheet, primary_key='Data')[source]
Parameters:
  • worksheet (Worksheet) – gspread.Worksheet

  • primary_key (str | tuple[str, ...]) –

    Primary key of the worksheet.

    If str type, it must be one of the column name.

    If tuple str type, the primary key is join using “_” per row

classmethod of(name, page, service_account_path, primary_key='Data')[source]

Get a worksheet from spreadsheet

Parameters:
  • name (str) – SpreadSheetName

  • page (str) – WorkPageName

  • service_account_path (str | Path | PathLike[str]) – The path to the service account json file

  • primary_key (str | tuple[str, ...]) –

    Primary key of the worksheet.

    If str type, it must be one of the column name.

    If tuple str type, the primary key is join using “_” per row

Returns:

GoogleWorkSheet

Return type:

GoogleWorkSheet

property title: str

WorkPageName

property headers: list[str]

list of worksheet header

property primary_key_list: list[str]

list of primary key of the worksheet

get_range_value(a1_range_notation)[source]

get values from range notation. i.e., B1:S1 to get the list of content.

If get values from 2D, the return order would be first column-wise, then row-wise

Parameters:

a1_range_notation (str)

Return type:

list[Any]

values(head)[source]

get list of value from header

Parameters:

head (str)

Return type:

list[Any]

get_cell(data, head, value_render_option='FORMATTED_VALUE')[source]

Get data from a cell

Parameters:
  • data (None | int | str | slice | list[int] | list[str] | ndarray) – DataIndex

  • head (str) – header name

  • value_render_option (Literal['FORMATTED_VALUE', 'UNFORMATTED_VALUE', 'FORMULA']) – VALUE_RENDER_OPT: {‘FORMATTED_VALUE’, ‘UNFORMATTED_VALUE’, ‘FORMULA’}

Returns:

update_cell(data, head, value)[source]

Update value in a cell

Parameters:
  • data (None | int | str | slice | list[int] | list[str] | ndarray) – DataIndex

  • head (str) – header name

  • value (list[str] | str) – value to be updated. str type if single field

Returns:

clear()[source]

Clears all cells in the worksheet

update(range_name, values=None, **kwargs)[source]

Sets values in a cell range of the sheet

to_pandas()[source]

Worksheet to pandas dataframe

Return type:

DataFrame

to_polars()[source]

Worksheet to polar dataframe

Return type:

DataFrame