I have a list of sentences say:
["Hello all, how are you doing?", "Hi all, wassup", "Namaste", "Bonjour, ca va", "Privet, kak dela?"...]
And I want to count the number of words per sentence and plot a histogram.
When I am counting individual items like:
seq = []
seq.append(len(X_train[0].split()))
seq
It gives me the result, which is fine. But, when I try for the whole hello list sequence of 28 sentences:
seq = [len(sentence.split()) for sentence in X_train]
I get the following error:
ttributeError Traceback (most recent call last)
<ipython-input-100-d9dec14bd2dd> in <module>()
----> 1 num_words = [len(sentence.split()) for sentence in X_train]
2 #pd.Series(seq_len).hist(bins = 30)
<ipython-input-100-d9dec14bd2dd> in <listcomp>(.0)
----> 1 num_words = [len(sentence.split()) for sentence in X_train]
2 #pd.Series(seq_len).hist(bins = 30)
AttributeError: 'float' object has no attribute 'split'
I have no clue why. Can you please explain?
Thanks!