Closed SerenaQYHuang closed 5 years ago
#check certain user name in the text
def check_name(x):
return 'ten_gop' in str(x).lower()
df['text'].apply(check_name).value_counts()
The output for this piece of code is like the following:
s_user = df['user_key'].value_counts()
df_users = s_user.reset_index()
#df_users
# count_retweeted_number of all the users with apply function
def count_retweeted_number(name):
def check_name(x):
return name in str(x).lower()
return df['text'].apply(check_name).value_counts().get(True, 0)
df_users['count'] = df_users['index'].apply(count_retweeted_number)
df_users.sort_values(by='count', ascending=False)
Output:
This is weird. Why doesn't it work?
processed_word_list = []
#assume you've already get a list of words
for word in words:
word = word.lower() # in case they are not all lower cased
if word not in stopwords:
processed_word_list.append(word)
@SerenaQYHuang the reason why the error appeared on several examples you listed above is that they are not the real example cases, its just a syntax without pulling data. I've already modified and make them real cases.
#check certain user name in the text def check_name(x): return 'ten_gop' in str(x).lower() df['text'].apply(check_name).value_counts()
The output for this piece of code is like the following:
for this error, it works in my environment, we can discuss more tomorrow.
type(str)
to see what you get. @SerenaQYHuang @ChicoXYC , you may have different results.
input: type(str) output: str
@ChicoXYC @hupili
Then I tried adding an r
before the url like this:
words = read_txt(r"C:\Users\Administrator\Dropbox\Media data analytics\BigDataAnalytics\AppleDaily.txt")
and it turned out to be:
but I copied the path from windows task manager
Is this comment resolved? It looks like mistakenly assignment to str
built-in function.
@hupili I guess this is the reason. Because in previous example, i use str
as an assignment. I've changed it into other name.
For the following code
What we expected was
"http://initiumlab.com/blog/20160730-mediawiki-wiki-knowledge-management-system/"
If we use the code listed above, what we actually got would be'http://initiumlab.com/20160730-mediawiki-wiki-knowledge-management-system/'
"/blog/" should be also added @ChicoXYC