Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

pandas -inf and inf to 0

df = pd.DataFrame({'team': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'],
                   'points': [18, np.inf, 19, np.inf, 14, 11, 20, 28],
                   'assists': [5, 7, 7, 9, 12, 9, 9, np.inf],
                   'rebounds': [np.inf, 8, 10, 6, 6, -np.inf, 9, 12]})
#replace inf and -inf with zero
df.replace([np.inf, -np.inf], 0, inplace=True)
df
	team	points	assists	 rebounds
0	A	18.0	5.0	 0.0
1	B	0.0	7.0	 8.0
2	C	19.0	7.0	 10.0
3	D	0.0	9.0	 6.0
4	E	14.0	12.0	 6.0
5	F	11.0	9.0	 0.0
6	G	20.0	9.0	 9.0
7	H	28.0	0.0	 12.0
Source by www.statology.org #
 
PREVIOUS NEXT
Tagged: #pandas #inf
ADD COMMENT
Topic
Name
5+7 =