-1

I have a dataframe named "df" that only have 1 column called "tweet". That dataframe consists of a bunch of sentences like this :

I have a cat
What do you mean by that?
This is my room.
Lorem ipsum dolor sit amet

I want to split all the sentences into words and put all the words into a list.

So far i tried :

def word_split() :
word = []
    for index, row in df.iterrows() :
        words = row['tweet'].split()
        word.append(words)
    return word

word_split() 

But rather than a list, i got a list of lists :

[['I', 'have', 'a', 'cat'],
['What', 'do', 'you', 'mean', 'by', 'that?'],
['This', 'is' .....]]

I want it to be a list rather than a list of lists :

['I', 'have', 'a', 'cat', 'What', 'do', 'you', .....]

Any suggestions?

bramd
  • 11
  • 4

1 Answers1

0

Rather than

word.append(words)

it must be

word.extend(words)

Thank you @jonrsharpe for the answer.

bramd
  • 11
  • 4