我有一个例子:
+---+---------+----+---------+---------+-------------+-------------+
|id | company |type|rev2016 | rev2017 | main2016 | main2017 |
+---+---------+----+---------+---------+-------------+-------------+
| 1 | google |web | 100 | 200 | 55 | 66 |
+---+---------+----+---------+---------+-------------+-------------+
我想要这个输出:
+---+---------+----+-------------+------+------+
|id | company |type| Metric | 2016 | 2017 |
+---+---------+----+-------------+------+------+
| 1 | google |web | rev | 100 | 200 |
| 1 | google |web | main | 55 | 66 |
+---+---------+----+-------------+------+------+
我试图实现的是将revenue和maintenance列转换为具有新列“metric”的行。到目前为止我还没找到运气。
1条答案
按热度按时间v7pvogib1#
可以从列构造一个结构数组,然后分解数组并展开结构以获得所需的输出。
或者你可以用
stack
: