Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Perform subtraction between pandas DataFrame column

I want to perform subtraction between pandas DataFrame columns.

I have below DataFrame:

min         max         type
166885599   166886548   IIT
173044132   173044947   IIT
173044398   173044398   dss1
173044411   173044411   dss2
173044424   173044424   dss3

The comparison has some condition which are below:

  1. "IIT" should be present present in the type column
  2. If "IIT" is present then the comparison will be like below:

For dss1:

min(abs(173044398 - 166885599),abs(173044398 - 166886548)) min(abs(173044398 - 173044132),abs(173044398 - 173044947))

For dss2:

min(abs(173044411 - 166885599),abs(173044411 - 166886548)) min(abs(173044411 - 173044132),abs(173044411 - 173044947))

and so on...

The output DataFrame should have below columns:

type    diff_output
dss1    corresponding_diff_value 
dss1    corresponding_diff_value
dss2    corresponding_diff_value
dss2    corresponding_diff_value
dss3    corresponding_diff_value
dss3    corresponding_diff_value

The comparison part is easy and I am done with that, but I stuck at the point when the type have more that one "IIT" values.

Comments