【发布时间】:2020-07-10 16:43:11
【问题描述】:
我有一个这样的数据框:
df = pd.DataFrame(
[
["True", "False"],
["True", "True"],
["False", "True"],
],
index=["bob", "sue", "joe"],
columns=["R1", "R2"],
)
我想把df融化,以便使用索引名称,并将Trues替换为列名,所以输出是这样的:
df = pd.DataFrame(
[
["bob", "R1"],
["sue", "R1"],
["sue", "R2"],
["joe", "R2"],
],
columns=["Names", "Role"],
)
我怎样才能做到这一点?
【问题讨论】:
标签: python-3.x pandas dataframe replace melt