I am doing a network analysis via networks and noticed that some of the nodes are being treated differently just because they have extra spaces (leading).
I tried to remove the spaces using the following codes but I cannot seem to make the output become strings again.
rhedge = pd.read_csv(r"final.edge.csv")
rhedge
_________________
source | to
niala | Sana, Sana
Wacko | Ana, Aisa
rhedge['to'][1]
'Sana, Sana'
rhedge['splitted_users2'] = rhedge['to'].apply(lambda x:x.split(','))
#I need to split them so they will be included as different nodes
The problem is with the next code
rhedge['splitted_users2'][1]
['Sana', ' Sana']
As you can see the second Sana has a leading space.
I tried to do this:
split_users = []
for i in split:
row = [x.strip() for x in i]
split_users.append(row)
pd.Series(split_users)
But when I am trying to split them by "," again, it won't allow me because the dataset is now list. I believe that splitting them would make networks treat them as one node as opposed to creating a different node for one with a leading space.
THANK YOU