我正在为外汇新闻分析创建一个基于实体的情绪分类。对于每一篇新闻文章,可能会有多种货币的标识。但是,我正在为如何将一行(如现有的人类标签中的{'USD':1, "JPY":-1}
)转换为单独的行而苦苦挣扎。在
示例数据帧现在是:
sentiment text
0 USD:1,CNY:-1 US economy is improving while China is struggling
1 USD:-1, JPY:1 Unemployment is high for US while low for Japan
希望转换成多行,如下所示:
^{pr2}$非常感谢你的帮助
您还可以尝试通过在
','
上拆分并使用melt
选项展开行来扩展情感。在输出:
^{pr2}$您可以构建一个新的数据帧,根据需要链接和重复值。在
结果:
^{pr2}$您可以在}
,|:
上拆分sentiment
列,然后展开^{然后使用^{} &;^{} 根据split的
len
重复text
列。在输出:
^{pr2}$相关问题 更多 >
编程相关推荐