3

I want to convert a dataframe to fasttext format

my dataframe

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

fast text format

__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

I tried df['label'].apply(lambda x: '__label__' + x).add_suffix(df['text']) But it doesn't work as I expected. How should I change my code ?

Osca
  • 1,588
  • 2
  • 20
  • 41

1 Answers1

6

Try:

'__label__'+df['label']+' '+df['text']
Nour-Allah Hussein
  • 1,439
  • 1
  • 8
  • 17