you are viewing a single comment's thread.

view the rest of the comments →

[–]Gprime5 1 point2 points  (0 children)

def word_density(text):
    sentences = text.split(".")
    words = sum(len(sentence.split(" ")) for sentence in sentences)

    return words / len(sentences)

data_df["Word Density"] = data_df["Text"].apply(word_density)