将数据帧转换为 fasttext 数据格式

Osc*_*sca 3 python pandas 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
Run Code Online (Sandbox Code Playgroud)

快速文本格式

__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
Run Code Online (Sandbox Code Playgroud)

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

小智 6

尝试:

'__label__'+df['label']+' '+df['text']
Run Code Online (Sandbox Code Playgroud)