Skip to main content
added 5 characters in body; edited title
Source Link
smci
  • 34.2k
  • 21
  • 118
  • 152

Replacing NaN values in a column from a second column

I would like to replace NaNNaN values in TargetTarget with the corresponding NodeNode value. My data is:

 Node Target Color node1 node7 Red node1 node9 Red node3 node5 Green node1 node3 Red node3 node1 Red node5 NaN Yellow 

I would need to have:

 Node Target Color node1 node7 Red node1 node9 Red node3 node5 Green node1 node3 Red node3 node1 Red node5 node5 Yellow # here the replacement 

I think that a possible solution could be using an if statement to check if a node has Target equal to NaN: if yes, thanthen it would be possible to assign itself as target.

Replacing NaN values in a column

I would like to replace NaN values in Target with the corresponding Node value. My data is

 Node Target Color node1 node7 Red node1 node9 Red node3 node5 Green node1 node3 Red node3 node1 Red node5 NaN Yellow 

I would need to have:

 Node Target Color node1 node7 Red node1 node9 Red node3 node5 Green node1 node3 Red node3 node1 Red node5 node5 Yellow # here the replacement 

I think that a possible solution could be using an if statement to check if a node has Target equal to NaN: if yes, than it would be possible to assign itself as target.

Replacing NaN values in a column from a second column

I would like to replace NaN values in Target with the corresponding Node value. My data is:

 Node Target Color node1 node7 Red node1 node9 Red node3 node5 Green node1 node3 Red node3 node1 Red node5 NaN Yellow 

I would need to have:

 Node Target Color node1 node7 Red node1 node9 Red node3 node5 Green node1 node3 Red node3 node1 Red node5 node5 Yellow # here the replacement 

I think that a possible solution could be using an if statement to check if a node has Target equal to NaN: if yes, then it would be possible to assign itself as target.

deleted 637 characters in body; edited title
Source Link
Math
  • 251
  • 2
  • 7
  • 24

Replacing NaN values in a column with another obs (from a different column)

MyI would like to replace NaN values in Target with the corresponding Node value. My data is

 Node Target Color node1 node7 Red node1 node9 Red node3 node5 Green node1 node3 Red node3 node1 Red node5 NaN Yellow 

I would like to treat nodes with no target (nan) as isolated nodes. Doing

from pymnet import * import matplotlib.pyplot as plt name='Layer1' mnet = MultilayerNetwork(aspects=1) for index in df.index: mnet[df.loc[index, 'Node'], df.loc[index, 'Target'], name,name] = 1 fig=draw(mnet, show=True, defaultLayerColor="whitesmoke", nodeSizeRule={"rule":"degree","propscale":0.05}, figsize=(25,30)) 

I have encountered the erroor

TypeError: 'Series' objects are mutable, thus they cannot be hashed

 (due to: ----> 9 mnet[df.loc[index, 'Node'], df.loc[index, 'Target'], name,name] = 1) 

I would say it is because of the nan value. I think that a possible solution could be using an if statement to check if a node has Target equal to NaN: if yes, than it would be possible to assign itself as target. Do you know how I could replace these values in orderneed to have:

 Node Target Color node1 node7 Red node1 node9 Red node3 node5 Green node1 node3 Red node3 node1 Red node5 node5 Yellow # here the replacement 

I think that a possible solution could be using an if statement to check if a node has Target equal to NaN: if yes, than it would be possible to assign itself as target.

Replacing NaN values in a column with another obs (from a different column)

My data is

 Node Target Color node1 node7 Red node1 node9 Red node3 node5 Green node1 node3 Red node3 node1 Red node5 NaN Yellow 

I would like to treat nodes with no target (nan) as isolated nodes. Doing

from pymnet import * import matplotlib.pyplot as plt name='Layer1' mnet = MultilayerNetwork(aspects=1) for index in df.index: mnet[df.loc[index, 'Node'], df.loc[index, 'Target'], name,name] = 1 fig=draw(mnet, show=True, defaultLayerColor="whitesmoke", nodeSizeRule={"rule":"degree","propscale":0.05}, figsize=(25,30)) 

I have encountered the erroor

TypeError: 'Series' objects are mutable, thus they cannot be hashed

 (due to: ----> 9 mnet[df.loc[index, 'Node'], df.loc[index, 'Target'], name,name] = 1) 

I would say it is because of the nan value. I think that a possible solution could be using an if statement to check if a node has Target equal to NaN: if yes, than it would be possible to assign itself as target. Do you know how I could replace these values in order to have:

 Node Target Color node1 node7 Red node1 node9 Red node3 node5 Green node1 node3 Red node3 node1 Red node5 node5 Yellow 

Replacing NaN values in a column

I would like to replace NaN values in Target with the corresponding Node value. My data is

 Node Target Color node1 node7 Red node1 node9 Red node3 node5 Green node1 node3 Red node3 node1 Red node5 NaN Yellow 

I would need to have:

 Node Target Color node1 node7 Red node1 node9 Red node3 node5 Green node1 node3 Red node3 node1 Red node5 node5 Yellow # here the replacement 

I think that a possible solution could be using an if statement to check if a node has Target equal to NaN: if yes, than it would be possible to assign itself as target.

edited title
Link
Math
  • 251
  • 2
  • 7
  • 24

Replacing NaN values in a column with their corresponding observation inanother obs (from a different column)

edited title
Source Link
Math
  • 251
  • 2
  • 7
  • 24
Loading
added 161 characters in body
Source Link
Math
  • 251
  • 2
  • 7
  • 24
Loading
Source Link
Math
  • 251
  • 2
  • 7
  • 24
Loading