【问题标题】:removing non English words from text in df.columns words contain letters and numbers从 df.columns 中的文本中删除非英语单词 单词包含字母和数字
【发布时间】:2020-05-28 15:07:04
【问题描述】:

如何去除 df.columns 中包含字母和数字的文本中的非英文单词

df['文本']

'the Interiors nrd studio |母亲节快乐“没有像母亲那样强大的影响力。” —sara josepha hale...母亲节快乐,妈妈和全世界所有的母亲!很多光娜塔莎
0wet3bxtfl'

'但仍然每天都想念你,母亲节快乐弗朗西斯·麦克拉弗蒂 (mccool) 9wlhju7cxf'

从以上 2 行中,我需要删除单词 '0wet3bxtfl' & '9wlhju7cxf'

【问题讨论】:

    标签: python nlp nltk preprocessor word


    【解决方案1】:

    该示例包括保留一些在英文单词列表中找不到的字符串(“nrd”、“mcclafferty”、“mccool”),同时删除“0wet3bxtfl”和“9wlhju7cxf”,因此预期结果可能是最好的方法是删除任何包含字母后跟数字或数字后跟字母(以及后面的任何空格)的非空白序列,而不考虑单词是否为“英语”。

    以下内容会这样做:

    import re
    
    ...
    
    filtered = re.sub('[^\s]*(\d[a-zA-Z]|[a-zA-Z]\d)[^\s]* *', '', df['text'])
    

    【讨论】:

      猜你喜欢
      • 2019-08-03
      • 2012-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-08
      • 2018-06-23
      • 1970-01-01
      相关资源
      最近更新 更多