我有这个 Dataframe :
Text feat1 feat2 feat3 feat4
string1 1 1 0 0
string2 0 0 0 1
string3 0 0 0 0
我想用这种方法创建另外两列:
Text feat1 feat2 feat3 feat4 all_feat count_feat
string1 1 1 0 0 ["feat1","feat2"] 2
string2 0 0 0 1 ["feat4"] 1
string3 0 0 0 0 [] 0
在Python中做这件事的最佳方法是什么?
列名可以是任何字符串。
3条答案
按热度按时间ijxebb2r1#
您可以用途:
q3qa4bjr2#
您可以使用
groupby
:输出:
inkz8wg93#
输出