Skip to content

Tmelt

flowtask.components.tMelt

tMelt

tMelt(loop=None, job=None, stat=None, **kwargs)

Bases: FlowComponent

tMelt

Overview

    The tMelt class is a component for transforming a DataFrame from a wide format to a long format using the
    Pandas `melt` function. It reshapes data by unpivoting columns, making it easier to analyze or process data
    with a simpler, long-form structure.

.. table:: Properties
:widths: auto

    +----------------+----------+-----------+---------------------------------------------------------------+
    | Name           | Required | Summary                                                                   |
    +----------------+----------+-----------+---------------------------------------------------------------+
    | index          |   Yes    | Column(s) to use as identifier variables for melting.                     |
    +----------------+----------+-----------+---------------------------------------------------------------+
    | name           |   No     | Name to use for the "variable" column in the result DataFrame.            |
    |                |          | Defaults to "name".                                                       |
    +----------------+----------+-----------+---------------------------------------------------------------+
    | value          |   No     | Name to use for the "value" column in the result DataFrame.               |
    |                |          | Defaults to "value".                                                      |
    +----------------+----------+-----------+---------------------------------------------------------------+
    | values         |   No     | List of columns to unpivot. If None, all remaining columns are used.      |
    +----------------+----------+-----------+---------------------------------------------------------------+

Returns

    This component returns a DataFrame in long format where specified columns are unpivoted to create two
    new columns: one for variable names (`name`) and one for values (`value`). Metrics on the row and column
    counts of the transformed DataFrame are recorded. Any errors during transformation are logged and raised
    with descriptive error messages.


Example:

```yaml
tMelt:
  index:
  - AL No.
  - Store Format
  name: product_name
  value: displays_quantity
```