Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert dataframe to fasttext data format

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 ?

like image 801
Osca Avatar asked Apr 28 '26 14:04

Osca


1 Answers

Try:

'__label__'+df['label']+' '+df['text']
like image 139
Nour-Allah Hussein Avatar answered May 01 '26 03:05

Nour-Allah Hussein