考虑到我有一个具有以下格式的熊猫数据文件。
Date Product cost|us|2019 cost|us|2020 cost|us|2021 cost|de|2019 cost|de|2020 cost|de|2021
01/01/2020 prodA 10 12 14 12 13 15
我们如何将其转换为以下格式
Date Product Year cost|us cost|de
01/01/2020 ProdA 2019 10 12
01/01/2020 ProdA 2020 12 13
01/01/2020 ProdA 2021 14 15
将非年份列按^{} 转换为} ,在^{} 中设置新列nmae,并按^{} 重新整形:
MultiIndex
,然后按最后一列按|
使用^{相关问题 更多 >
编程相关推荐