首页 > 解决方案 > 将数据帧转换为 fasttext 数据格式

问题描述

我想将数据框转换为 fasttext 格式

我的数据框

text                                                             label 
Fan bake vs bake                                                 baking
What's the purpose of a bread box?                               storage-method
Michelin Three Star Restaurant; but if the chef is not there     restaurant

快速文本格式

__label__baking Fan bake vs bake
__label__storage-method What's the purpose of a bread box?
__label__restaurant Michelin Three Star Restaurant; but if the chef is not there

我试过df['label'].apply(lambda x: '__label__' + x).add_suffix(df['text']) 了,但它没有像我预期的那样工作。我应该如何更改我的代码?

标签: pythonpandasfasttext

解决方案


尝试:

'__label__'+df['label']+' '+df['text']

推荐阅读