0
我有一个像下面的一个Python熊猫数据帧:Python的大熊猫多列组合到单个列
movie unknown action adventure animation fantasy horror romance sci-fi
Toy Story 0 1 1 0 1 0 0 1
Golden Eye 0 1 0 0 0 0 1 0
Four Rooms 1 0 0 0 0 0 0 0
Get Shorty 0 0 0 1 1 0 1 0
Copy Cat 0 0 1 0 0 1 0 0
我想这部电影流派结合成一个烧毛列。输出会是这样:
movie genre
Toy Story action, adventure, fantasy, sci-fy
Golden Eye action, romance
Four Rooms unknown
Get Shorty animation, fantasy, romance
Copy Cat adventure, horror
'df ['genre'] = df.apply(lambda x:df.columns [x.astype(bool)]。tolist()[1:],axis = 1)+1并同意它不会提供任何额外的好处 – bernie
@bernie,谢谢:) – MaxU