How it works...
The pandas library has plenty of built-in operations to return the desired mathematical and statistical computations over the indicated axis, that is, across the rows or the columns of a dataframe. In this recipe, we leveraged the power of pandas to create new features from existing ones. We loaded the Breast Cancer dataset from scikit-learn. Then, we made a list of the features to combine with the multiple mathematical operations. We used the pandas sum(), prod(), mean(), std(), max(), and min() methods to determine the sum, product, mean, standard deviation, and maximum and minimum values of those features.
To perform these operations across the columns, that is, across the variables, we added the axis=1 argument within ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access