Skip to main content
 首页 » 编程设计

python之如何将列更改为行

2025年05月04日22tuyile006

<分区>

我有这个数据框:

Name  type1  type2  type3  ...  typeN  color 
 
John  8.7  0  NA  ...  56  blue 
 
Andy  45  34  9.7  ...  NA  yellow 

我需要将其更改为:

color  typeName  Name  value 
blue  type1  John  8.7 
blue  type2  John  0 
blue  type3  John  NA 
. 
. 
. 
blue  typeN  John  56 
yellow  type1  Andy  45 
yellow  type2  Andy  34 
yellow  type3  Andy  9.7 
. 
. 
. 
yellow  typeN  Andy  NA 

我对如何做到这一点有点困惑,有什么帮助吗?