How it works...

In this recipe, we replaced negative values with zero. To proceed with the recipe, we first created a toy dataframe with three independent variables that were normally distributed and showed a few negative values. Next, we examined the presence of negative values in the variables by looking at the minimum values and plotting the histograms. Finally, we replaced the negative values with 0.

To generate the toy dataframe, first, we created three independent variables, x, y, and z, which are normally distributed. We used NumPy's random.randn(), which extracts values at random from a normal distribution, and we multiplied the extracted values by a factor and added a constant value, to make the variables slightly different. Next, ...

Get Python Feature Engineering Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.