There is a large data frame name dataframe1. for example(just a few):
date text name
1 I like you hair, do you like it screen1
2 beautiful sun and wind screen2
3 today is happy, I want to got school screen3
4 good movie screen4
5 thanks god screen1
6 you are my son and I love you screen2
7 the company is good screen1
8 no one can help me, only you screen2
9 the book is good and I read it everyday screen3
10 water is the source of love screen4
11 I like you hair, do you like it screen1
12 my love man is leaving screen2
I want to calculate the number of the words of each name's text(such as all the screen1's text in the dataframe1) use the function count_noun(str). Further, the con_noun(str) is ok and finished.
I want to extract all the text which have the same name in the data frame and calculate the noun counts. Please don't focus on the function count_noun(str), and I have finished it.
My code:
import pandas as pd
import numpy as np
screen_name_unique = list(set(dataframe1['name']))
for name in screen_name_unique:
dataframe_text = dataframe1[dataframe1.name == name]
count = noun_count(dataframe['text'])
def noun_count (str):
words_len = len(str)
return words_len
I found it is wrong and don't know how to solve it, for example extract all the name1's text to be string and send it to function: noun_count(str), please give me your hand, thanks!