Python Machine Learning Blueprints
上QQ阅读APP看书,第一时间看更新

applymap

We've looked at manipulating columns and explained how to work with rows, but suppose you'd like to perform a function across all data cells in your DataFrame. This is where applymap is the correct tool. Let's take a look at an example:

Using applymap function

Here, we called applymap on our DataFrame in order to get the log of every value (np.log() utilizes the NumPy library to return this value), if that value is of the float type. This type checking prevents returning an error or a float for the species or wide petal columns, which are string and integer values respectively. Common uses of applymap include transforming or formatting each cell based on meeting a number of conditional criteria.