content/flux/v0/stdlib/experimental/unpivot.md
experimental.unpivot() creates _field and _value columns pairs using all columns (other than _time)
not in the group key.
The _field column contains the original column label and the _value column
contains the original column value.
The output stream retains the group key and all group key columns of the input stream.
_field is added to the output group key.
(<-tables: stream[{A with _time: time}], ?otherColumns: [string]) => stream[{B with _value: C, _field: string}] where A: Record, B: Record
{{% caption %}} For more information, see Function type signatures. {{% /caption %}}
Input data. Default is piped-forward data (<-).
List of column names that are not in the group key but are also not field columns. Default is ["_time"].
import "experimental"
data
|> experimental.unpivot()
{{< expand-wrapper >}} {{% expand "View example input and output" %}}
| _time | *location | temp | hum |
|---|---|---|---|
| 2022-01-01T00:00:00Z | Denver | 10.2 | 81.5 |
| 2022-01-02T00:00:00Z | Denver | 12.4 | 41.3 |
| _time | *location | temp | hum |
|---|---|---|---|
| 2022-01-01T00:00:00Z | New York | 50.1 | 99.2 |
| 2022-01-02T00:00:00Z | New York | 55.8 | 97.7 |
| *location | *_field | _time | _value |
|---|---|---|---|
| Denver | hum | 2022-01-01T00:00:00Z | 81.5 |
| Denver | hum | 2022-01-02T00:00:00Z | 41.3 |
| *location | *_field | _time | _value |
|---|---|---|---|
| New York | hum | 2022-01-01T00:00:00Z | 99.2 |
| New York | hum | 2022-01-02T00:00:00Z | 97.7 |
| *location | *_field | _time | _value |
|---|---|---|---|
| Denver | temp | 2022-01-01T00:00:00Z | 10.2 |
| Denver | temp | 2022-01-02T00:00:00Z | 12.4 |
| *location | *_field | _time | _value |
|---|---|---|---|
| New York | temp | 2022-01-01T00:00:00Z | 50.1 |
| New York | temp | 2022-01-02T00:00:00Z | 55.8 |
{{% /expand %}} {{< /expand-wrapper >}}