How can I rearrange df as the nodes index in pytorch geometric manner?
This is my code
Source Source Source Target Target Source Source Target Target
4 4 4 4 4 1 1 1 1
0 2 3 1 6 2 2 6 7
Label Rainfall Inflow SWT SP2 Evp Inflow Inflow Evp Outflow
This is my code
data = {'Source': ['Rainfall', 'SP2', 'SP2', 'Inflow','Rainfall','Inflow', 'Inflow', 'Inflow','SWT','SP1','SP1','SWD'], 'Target': ['SP1', 'Evp', 'Outflow', 'SP2','SWD','SWD', 'SP2','SP1','SP1','SP2','Evp','Loss']} df = pd.DataFrame(data) nodes = pd.concat([df['Source'], df['Target']]).unique() node_indices = {node: i for i, node in enumerate(nodes)} df['Source'] = df['Source'].map(node_indices) df['Target'] = df['Target'].map(node_indices)My goal is to generate the following outputs:
Source Source Source Target Target Source Source Target Target
4 4 4 4 4 1 1 1 1
0 2 3 1 6 2 2 6 7
Label Rainfall Inflow SWT SP2 Evp Inflow Inflow Evp Outflow