Python Forum
How can I rearrange df as the nodes index in pytorch geometric manner?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I rearrange df as the nodes index in pytorch geometric manner?
#1
How can I rearrange df as the nodes index in pytorch geometric manner?

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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Get the value of arcsine(x) in a manner that I can understand. Pedroski55 4 815 May-22-2023, 06:43 AM
Last Post: Gribouillis
  Python3 binary tree not replacing parent nodes with child nodes Aspect11 0 1,786 Sep-23-2020, 02:22 PM
Last Post: Aspect11
  read individual nodes from an xml url using pandas mattkaplan27 5 2,958 Jul-05-2020, 10:06 PM
Last Post: snippsat
  Installing Pytorch Godserena 4 2,674 Jul-02-2020, 06:44 PM
Last Post: hussainmujtaba
  Modifying anytree Nodes gw1500se 1 2,664 Jun-05-2020, 03:44 PM
Last Post: Gribouillis
  Rearrange Columns in a CSV File rjj920 1 5,601 May-09-2020, 03:26 PM
Last Post: DPaul
  what does code mean (python, pytorch) sveto4ka 2 2,300 Mar-12-2020, 04:26 PM
Last Post: sveto4ka
  Animate graph nodes inside a function adamG 0 2,960 Sep-23-2019, 11:18 AM
Last Post: adamG
  how to rearrange text Prince_Bhatia 1 2,541 Mar-07-2019, 01:58 PM
Last Post: ichabod801
  Comms for multiple nodes. MuntyScruntfundle 1 1,903 Feb-18-2019, 03:54 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020