set_flat_column

set_flat_column#

NestSeriesAccessor.set_flat_column(column: str, value: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | complex | bytes | str | _NestedSequence[complex | bytes | str]) NestedSeries[source]#

Set the column from flat-array of values and return a new series

Parameters:
  • column (str) – Name of the column to set. If not present, it will be added.

  • value (ArrayLike) – Array of values to set. It must be a scalar or have the same length as the flat arrays, e.g. self.flat_length.

Returns:

The new series with the field set.

Return type:

NestedSeries

Examples

>>> from nested_pandas.datasets.generation import generate_data
>>> nf = generate_data(5, 2, seed=1)
>>> nested_with_avg = nf["nested"].nest.set_flat_column("avg_flux",
...                                                     50.0)
>>> # Look at one row of the series
>>> nested_with_avg[0]
          t       flux  flux_error band  avg_flux
0   8.38389  80.074457         1.0    r      50.0
1  13.40935  89.460666         1.0    g      50.0