geost.base.Collection.add_columns#

Collection.add_columns(columns: dict = None, to: str = 'data', inplace: bool = False, **kwargs) → Collection | None[source]#

Add columns to the header or data table of the Collection.

Adds new columns to either the header or data table using pandas.DataFrame.assign(). The columns can be provided either as a dictionary or as keyword arguments.

Parameters:
  • columns (dict, optional) – Dictionary of column names and values to add, can also be provided as keyword arguments (see **kwargs). The default is None.

  • to (str, optional) – Table to add columns to, either “data” or “header”. The default is “data”.

  • inplace (bool, optional) – If True, modify the current Collection and return None. If False, return a new Collection with the added columns. The default is False.

  • **kwargs – Columns to add, provided as keyword arguments. These are merged with the columns dictionary.

Returns:

If inplace=False, returns a new Collection instance with the added columns. If inplace=True, returns None and modifies the current Collection.

Return type:

Collection or None

Raises:

ValueError – If to is not “data” or “header”.

Examples

Add a single column to the data table using keyword arguments:

>>> collection_new = collection.add_columns(column_name=new_values)

Add multiple columns to the header table in place:

>>> collection.add_columns(
...     columns={"column1": values1, "column2": values2},
...     to="header",
...     inplace=True
... )

Get the same result with providing them as kwargs:

>>> collection.add_columns(column1=values1, column2=values2, to="header", inplace=True)