| title |
description |
menu |
weight |
flux/v0/tags |
introduced |
| experimental.unpivot() function |
`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.
|
| flux_v0_ref |
| name |
parent |
identifier |
| experimental.unpivot |
experimental |
experimental/unpivot |
|
|
101 |
|
0.172.0 |
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.
Function type signature
(<-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 %}}
Parameters
tables
Input data. Default is piped-forward data (<-).
otherColumns
List of column names that are not in the group key but are also not field columns. Default is ["_time"].
Examples
Unpivot data into _field and _value columns
import "experimental"
data
|> experimental.unpivot()
{{< expand-wrapper >}}
{{% expand "View example input and output" %}}
Input data
| _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 |
Output data
| *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 >}}