July 2017
Beginner to intermediate
312 pages
7h 27m
English
In this section, we will follow a similar logic to create our graph, but we will engineer the nodes and edges differently to obtain the relationship that we are looking for.
We create a list of topics which will be used to build the links:
columns = [t[0] for t in frequency]
Then, we create a list of usernames that are stored as an index in our dataframe:
usernames = users.index.tolist()
We merge lists of cleaned tokens into a string:
users['clean_join'] = users['clean'].apply(lambda x: " ".join(x))
For each topic, we create a Boolean variable to check if a topic was expressed by a user and we store this information in a topic column:
for column in columns: users[column] = users['clean_join'].str.lower().str.contains(column) ...
Read now
Unlock full access