Anjali Kushwaha
Anjali Kushwaha

Reputation: 43

Divide a column(containing both negative numbers and positive numbers) of a Pandas Dataframe with a specific number and create a new column in python?

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 ?

Upvotes: 1

Views: 376

Answers (1)

jezrael
jezrael

Reputation: 862801

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

Upvotes: 1

Related Questions