将二进制编码转换为多标签python类
我在dataframe中有这样的数据 正文 标签1 标签2 标签3 标签4 标签 你好,我叫约翰 1. 0 1. 0将二进制编码转换为多标签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.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']的拼写错误,您能确认吗?是的,很抱歉,这是一个拼写错误。。编辑。谢谢