Python Forum
Question for dataframe to replace INF value - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Question for dataframe to replace INF value (/thread-7555.html)



Question for dataframe to replace INF value - zydjohn - Jan-15-2018

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,