摘要:我的代码输出提供了一个以下格式的数据帧。dataframe的列标题是Content
列中文本的标签。在下一步中,这些标签将作为多标签分类器的训练数据。这是一段更大的实际数据。在
因为它们是列标题,所以不可能将它们映射到作为其标签的文本。在
Content A B C D E
zxy 1 2 1
wvu 1 2 1
tsr 1 2 2
qpo 1 1 1
nml 2 2
kji 1 1 2
hgf 1 2
edc 1 2 1
更新:将df转换为csv显示空单元格为空(''
vs' '
):
其中Content
是文本所在的列,A
、B
、C
、D
、和{
更新:经过一番挖掘,也许数字不是整数,而是字符串。在
我知道在将文本+标签输入分类器进行处理时,两个数组的长度必须相等,否则不能将其视为有效输入。在
有没有一种方法可以将DF中Content
中文本的列标题转换为标签?在
预期输出:
^{pr2}$
完整解决方案:
我们可以做^{} ,注意这里,我将空格视为
^{pr2}$np.nan
,如果你的数据中是一个真正的空白,请更改最后一行您也可以按如下方式进行操作:
输出如下:
^{pr2}$给出以下输入数据:
编辑:我刚刚在阅读完之后删除了
'idx'
,创建了一个类似于原始数据帧的结构,并添加了一些可以处理不同数据类型的故障保护代码(melt方法下面的两行)。如果对缺失值的实际表示方式了解得更多,代码就可以简化。在下面是另一种使用
np.where
和groupby
的方法:输出:
^{pr2}$相关问题 更多 >
编程相关推荐