【问题标题】:Splitting words in a column拆分列中的单词
【发布时间】:2019-03-20 00:34:43
【问题描述】:

我有一个带有 msg 列的 csv,它有以下文本

muchloveandhugs                                  
dudeseriously                                    
onemorepersonforthewin                           
havefreebiewoohoothankgod                        
thisismybestcategory                             
yupbabe                                          
didfreebee                                       
heykidforget                                     
hecomplainsaboutit                               

我知道 nltk.corpus.words 有一堆有意义的词。我的问题是如何在 df['msg'] 列上对其进行迭代,以便获得诸如

之类的单词
df[‘msg’]
much love and hugs
dude seriously
one more person for the win

【问题讨论】:

  • 这个问题很广泛,没有很好的定义。比如someone是一个字还是some one?您应该分享您现有的代码,以便从某个地方开始。
  • 这是一个复杂的问题并且容易出错,因为它严重依赖概率。我发现this link 提出了一种方法。就个人而言,我很想问问谷歌;它将拆分这些字符串并提供“你的意思是”链接。

标签: python regex nlp nltk


【解决方案1】:

来自this question 关于在没有空格的字符串中拆分单词并且不太了解您的数据是什么样的:

import pandas as pd
import wordninja

filename = 'mycsv.csv' # Put your filename here

df = pd.read_csv(filename)
for wordstring in df['msg']:
    split = wordninja.split(wordstring)
    # Do something with split

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-15
    • 2019-03-12
    • 2017-08-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多