Search
 
SCRIPT & CODE EXAMPLE
 

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
Comment

PREVIOUS NEXT
Code Example
Python :: int to alphabet letter python 
Python :: flask error handling 
Python :: python get element from dictionary 
Python :: move file python os 
Python :: how to capture cmd output in python 
Python :: python array 
Python :: python timer() 
Python :: pandas filter rows that are in a list 
Python :: python list add element to front 
Python :: python program to find numbers divisible by another number 
Python :: how to select axis value in python 
Python :: Python program to print negative numbers in a list 
Python :: how to log errors while debug is false in django 
Python :: find an index of an item in a list python 
Python :: from django.http import HttpResponse 
Python :: filter a pandas dataframe by length of list in a column 
Python :: numpy array sorting 
Python :: sum of list in python 
Python :: python print last 3 
Python :: how to use .format in python 
Python :: input python 3 
Python :: python - regexp to find part of an email address 
Python :: convert tensor to numpy array 
Python :: convert string to lowercase python 
Python :: python convert json string to class 
Python :: any in python 
Python :: scrapy proxy pool 
Python :: get all files in pc python 
Python :: how to split a string with newline in python 
Python :: python glfw 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =