Skip to main content
 首页 » 编程设计

python之合并重复的列 Pandas

2024年10月01日7xiaohuochai

我正在寻找一种合并重复列的方法,假设空白为 NaN

Column1[1]  Column1[2]  Column1[3]  Column1[4]  Column1[4]  Column1[5]  Column1[6]  Column1[7] 
  a 123                          
  b            432                       
  c                         53                   
  d                                 221              
  e                                                 2            
  f                                                             3        
  g                                                                         3243     
  h                                                                                     12 

输出应该是这样的

  Row   Column1[ALL] 
  a 123 
  b 432 
  c 53 
  d 221 
  e 2 
  f 3 
  g 3243 
  h 12 

请您参考如下方法:

如果 df 是您的数据框:

df.max(axis=1)