Questions
Questions

Reputation: 75

Splitting words in a column

I have a csv with msg column and it has the following text

muchloveandhugs                                  
dudeseriously                                    
onemorepersonforthewin                           
havefreebiewoohoothankgod                        
thisismybestcategory                             
yupbabe                                          
didfreebee                                       
heykidforget                                     
hecomplainsaboutit                               

I know that nltk.corpus.words has a bunch of sensible words. My problem is how do I iterate it over the df[‘msg’] column so that I can get words such as

df[‘msg’]
much love and hugs
dude seriously
one more person for the win

Upvotes: 0

Views: 348

Answers (1)

Stephen C
Stephen C

Reputation: 2036

From this question about splitting words in strings with no spaces and not quite knowing what your data looks like:

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

Upvotes: 2

Related Questions