python takes a certain value in the array elements replace all other elements of the methods

The problem here is doing House Price Prediction when it came, try to do GarageArea log transformation, but due to some houses no garage, so GarageArea = 0, then became -inf by log transformation, so I want all - inf data is converted back to all 0, as shown in the title.

In addition to recycling can also how to do it? Look at the following code

train_test['GarageArea'] = np.log(train_test['GarageArea'])

train_test['GarageArea'] = train_test['GarageArea'].replace(float("-inf"), 0)

Originally thought replace () function is a specific function str, try to discover the results can also be used in the array, where special -inf is written, can not be directly written -inf or '-inf', and to write float ( "- inf ")

Guess you like

Origin www.cnblogs.com/RB26DETT/p/11610345.html