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