1

A = 49531.78, -3.178 ,-2.119

Want to divide A's value with 49939.203 , used formula in excel =IFERROR(49939.203/A1,0) B should be => 1.01;-15714.04; -23567.35 , how should I do in python to get this division ?

1 Answers1

1

Use Series.rdiv for divide from right side:

df['B'] = df.A.rdiv(49939.203).replace(np.inf, 0).round(2)
print (df)
           A         B
0  49531.780      1.01
1     -3.178 -15714.03
2     -2.119 -23567.34
3      0.000      0.00
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
  • Thanks for this response, How to handle 0 if in A column ? Want the negative signs as well in B? @https://stackoverflow.com/users/2901002/jezrael – Anjali Kushwaha Jan 17 '22 at 14:23
  • @AnjaliKushwaha - you can use `replace` like `df['B'] = df.A.abs().rdiv(49939.203).replace(np.inf, 0).round(2)` – jezrael Jan 17 '22 at 14:25
  • Now i want to divide this B column like this ---- =IFERROR(691.525/B,0). Will this above logic work, like denominator and numerator is changed little??? – Anjali Kushwaha Jan 17 '22 at 14:45
  • @AnjaliKushwaha - sure, if change `49939.203` to `691.525` it working well – jezrael Jan 17 '22 at 14:46
  • Thanks alot, its working, may i know what is rdiv() function really do? – Anjali Kushwaha Jan 17 '22 at 14:48
  • @https://stackoverflow.com/users/2901002/jezrael, how to convert this series to normal dataframe column as I am getting exponential format in few values? – Anjali Kushwaha Jan 19 '22 at 18:28
  • @AnjaliKushwaha - `what is rdiv() function really do` ? `df.A.rdiv(49939.203)` is same like `49939.203 / df.A` divide from right side – jezrael Jan 20 '22 at 06:35
  • @AnjaliKushwaha - it is more complicated, check [this](https://stackoverflow.com/questions/21137150/format-suppress-scientific-notation-from-python-pandas-aggregation-results) for remove `exponential format` – jezrael Jan 20 '22 at 06:36