So I have a bit of a silly question, but being fairly new to Python, I can't seem to find the answer to it myself. I extracted verb phrases using spaCy's matcher. Now, I'm hoping to get the mean number of words in the extracted verb phrases for each person's text and stored them in a new dataframe column. In order to do this, I'm trying to create a function that I'll then apply to said dataframe column.
I created this function:
def get_length_phrases(column):
for phrase in column:
phrase_length = len(phrase)
mean_length = np.mean(phrase_length)
return mean_length
The problem is, when I apply it to the column in which the verb phrases are stored, I get an output that looks like this :
0 1.0
1 1.0
2 1.0
3 1.0
4 1.0
...
235 1.0
236 1.0
237 1.0
238 1.0
239 1.0
Name: verb_phrases_length, Length: 240, dtype: float64
The problem is, there is way more than one word per phrase, so clearly, I'm doing something wrong, but can't seem to figure out what... statistics.mean doesn't work either...