【问题标题】:How to create a single column with all the relevant text?如何创建包含所有相关文本的单列?
【发布时间】:2021-01-03 17:54:36
【问题描述】:

我有一个数据集enter image description here,我想创建一个带有标题和文本的单列。我试着写这样的代码:

df['text'] = df['title'] +" "+ df['text']

#Delete all the other columns.
  del df['title'] # added to text corpus
  del df['subject'] # it would affect results
  del df['date']

但它不工作,我得到错误。 enter image description here

【问题讨论】:

  • 你能做一个df.columns 并检查title 前后是否有空格?
  • 另外,对以后的帖子的建议,只需复制并粘贴数据框而不是添加图像:)

标签: python machine-learning scikit-learn compiler-errors calculated-columns


【解决方案1】:

我认为您正在寻找的行是:

df['new_text'] = df['title'].str.cat(df['text'],sep=" ")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-28
    相关资源
    最近更新 更多