Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将二进制编码转换为多标签python类_Python_Dataframe_Machine Learning - Fatal编程技术网

将二进制编码转换为多标签python类

将二进制编码转换为多标签python类,python,dataframe,machine-learning,Python,Dataframe,Machine Learning,我在dataframe中有这样的数据 正文 标签1 标签2 标签3 标签4 标签 你好,我叫约翰 1. 0 1. 0 好的,这是一个未经验证的建议。尝试收集适当的列标签,然后在适当的函数上使用DataFrame.apply: test_cols=[c代表df.columns中的c,如果c[:5]。lower()=='label'] 删除测试列(“标签”) def凝聚标签(aSeries): 返回[lab for lab in test_cols如果一系列[lab]==1] df['Labels'

我在dataframe中有这样的数据

正文 标签1 标签2 标签3 标签4 标签 你好,我叫约翰 1. 0 1. 0
好的,这是一个未经验证的建议。尝试收集适当的列标签,然后在适当的函数上使用DataFrame.apply:

test_cols=[c代表df.columns中的c,如果c[:5]。lower()=='label']
删除测试列(“标签”)
def凝聚标签(aSeries):
返回[lab for lab in test_cols如果一系列[lab]==1]
df['Labels']=df.apply(聚合标签,轴=1)

正如我所说,这是未经检验的;可能需要对代码进行调整。

值已准备好,没有公式可供选择我认为['Label1','Label2']是一个应为['Label1','Label3']的拼写错误,您能确认吗?是的,很抱歉,这是一个拼写错误。。编辑。谢谢