Python Forum

Full Version: Question for dataframe to replace INF value
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
import pandas as pd
df1 = pd.DataFrame({'a': [1.0, 1.1, 1.2 ], 'b': [ 0.5, 1.1, 1.0 ]})
mid = (df1['a'] + df1['b']) / 2.0
aMid = df1['a'].sub(mid)
bMid = df1['b'].sub(mid)
aWid = (a1 / aMid)
bWid = (a1 / bMid)
print(aWid)
print(bWid)
I want to replace the INF result in aWid or bWid, where the result is divided by 0, and replace the INF result by 0.0
Please help.
Thanks,