【1.4】Pandas学习—pandas对列进行合并

列直接拼接

import pandas as pd

df_id = pd.read_excel('C:/Users/Administrator.USER-20160219OS/Desktop/id.xlsx',sheetname='mbrole_conversion')
print(df_id.head(3))
print('----------------------------------------------------------------------------------')
df_id['new_column'] = df_id['Output ID']+'('+df_id['Input ID'].map(str)+'|'+df_id['FC'].map(str)+')'
print(df_id.head(3))

结果如下:

       Input ID       IDsource Output ID  \
0                              PC(15:0/18:2(9Z,12Z))  Chemical name    C00157   
1  1-Hexadecanoyl-2-(9Z-octadecenoyl)-sn-glycero-...  Chemical name    C00157   
2                                 PC(14:0/18:1(11Z))  Chemical name    C00157   

  Red/Blue        FC source of the output ID  
0     blue  0.415800                    KEGG  
1     blue  0.414033                    KEGG  
2     blue  0.274952                    KEGG  
----------------------------------------------------------------------------------
                                            Input ID       IDsource Output ID  \
0                              PC(15:0/18:2(9Z,12Z))  Chemical name    C00157   
1  1-Hexadecanoyl-2-(9Z-octadecenoyl)-sn-glycero-...  Chemical name    C00157   
2                                 PC(14:0/18:1(11Z))  Chemical name    C00157   

  Red/Blue        FC source of the output ID  \
0     blue  0.415800                    KEGG   
1     blue  0.414033                    KEGG   
2     blue  0.274952                    KEGG   

                                          new_column  
0   C00157(PC(15:0/18:2(9Z,12Z))|0.4157996129822089)  
1  C00157(1-Hexadecanoyl-2-(9Z-octadecenoyl)-sn-g...  
2     C00157(PC(14:0/18:1(11Z))|0.27495187889755845)
列拼接可直接转成字符串进行拼接,利用.map(str)函数进行转换


猜你喜欢

转载自blog.csdn.net/weixin_30935137/article/details/80875542
今日推荐