python - 将数据帧转换为快速文本数据格式

标签 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

快速文本格式

__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']) 但它没有像我预期的那样工作。我应该如何更改我的代码?

最佳答案

尝试:

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

关于python - 将数据帧转换为快速文本数据格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65102525/

相关文章:

python - Pandas > 统计模型 : syntax errors implementing variance_inflation_factor

python - 类型错误 : ("sort_values() got multiple values for argument ' axis '", ' occurred at index SUMLEV')

python - 合并两个数据帧并分别添加 resp 列

python - 我有两个相同的 CSV 文件,但由于 UnicodeDecodeError,其中一个无法读入 Pandas DataFrame

python - 在 Windows 中测试时,使用 fasttext api 的监督分类返回空数组

machine-learning - 如何使用 gensim fasttext 包装器训练词嵌入表示?

python - (Python)尽可能快地计算一个巨大(> 10GB)文件中的行数

python - 如何有效地在具有不同维度的多维 numpy 数组中添加列?

python - fasttext 无法加载训练 txt 文件

Python IMAP 搜索,搜索结果耗尽所有内存