【发布时间】:2020-12-15 10:16:19
【问题描述】:
无法弄清楚如何通过几个二进制列值将我的 DataFrame 重塑为新的。
输入:
data code a b c
2016-01-07 foo 0 0 0
2016-01-12 bar 0 0 1
2016-01-03 gar 0 1 0
2016-01-22 foo 1 1 0
2016-01-26 bar 1 1 0
我想通过二进制值重塑,即列 a/b/c,如果它们的值 == 1,我每次都需要新列 包含所有数据。
预期输出:
data code
a 2016-01-22 foo
a 2016-01-26 bar
b 2016-01-03 gar
b 2016-01-22 foo
b 2016-01-26 bar
c 2016-01-12 bar
从早上就卡在这里,非常感谢帮助!
【问题讨论】:
标签: python pandas dataframe numpy reshape