在保留相关列中的值时熔化

时间:2015-10-07 20:09:41

标签: python pandas

我有一个这样的数据框:

           POLY_KEY_I  SP1_Percent  SP2_Percent SP1_LOWER SP2_LOWER
0     FS01080100SM001         12.5         12.5    POAPRA    TOXRYD
1     FS01080100SM001          0.0          0.0       NaN       NaN
2     FS01080100SM001          2.5          2.5    TOXRYD    SYMOCC
3     FS01080100SM001         20.0         20.0    EUPESU    POAPRA
4     FS01080100SM001         12.5         12.5    BOUGRA    KOEPYR
5     FS01080100SM002         22.5         22.5    POAPRA    EUPESU
6     FS01080100SM002         12.5          0.0    POAPRA       NaN
7     FS01080100SM002         15.0         15.0    POAPRA    KOEPYR

我希望根据SP1_Lower融化SP2_LowerPOLY_KEY_I,但我想保留关联的SP1_PercentSP2_Percent。我可以用它来融化它:

df=pd.melt(df, id_vars='POLY_KEY_I', value_vars=['SP1_LOWER', 'SP2_LOWER'], value_name='SP')

但我想要的输出是:

         POLY_KEY_I variable      SP   Percent
0   FS01080100SM001      SP1  POAPRA   12.5
1   FS01080100SM001      SP1     NaN   0
2   FS01080100SM001      SP1  TOXRYD   2.5
3   FS01080100SM001      SP1  EUPESU   20.0
4   FS01080100SM001      SP1  BOUGRA   12.5
5   FS01080100SM002      SP1  POAPRA   22.5
6   FS01080100SM002      SP1  POAPRA   12.5
7   FS01080100SM002      SP1  POAPRA   15.0
8   FS01080100SM001      SP2  TOXRYD   12.5
9   FS01080100SM001      SP2     NaN   0
10  FS01080100SM001      SP2  SYMOCC   2.5
11  FS01080100SM001      SP2  POAPRA   20.0
12  FS01080100SM001      SP2  KOEPYR   12.5
13  FS01080100SM002      SP2  EUPESU   22.5
14  FS01080100SM002      SP2     NaN   0
15  FS01080100SM002      SP2  KOEPYR   15.0

1 个答案:

答案 0 :(得分:1)

您可以创建每个子部分的DataFrame,然后将它们连接在一起:

texture2D(u_texture, v_texCoords);