I have a big csv file containing connected data such as:
Source,Target
a,token
b,token2
c,token3
d,j
e,k
f,l
token,g
token2,h
token3,i
the structure of the file is mixed, so the rows where the relation is
a,token
b,token2
c,token3
do not identify specific relations in the network graph, but instead define aliases to which the entities a, b and c are mapped.
In the rest of the file, i have standard relations (d,j; e,k; f,l) but also relations where the real name of the entity is replaced by its alias:
token,g
token2,h
token3,i
Currently, I am looping over the file with ugly 'for' loops and in such a way I am able to map the relations in the desired way and to get:
a,g
b,h
c,i
but it's not an elegant way and, perhaps, heavy on my cpu.
Is there any built-in function (maybe in pandas) or some elegant and quick way (few lines of code) to map the file as desidred in Python?