pandas module - the difference between map(), apply() and applymap() methods

  1. map()
    • Apply a custom function to each element of the Series object
    • The map() method can only be used on Series objects, and the DataFrame object does not have a map() method
  2. apply()
    • Apply a custom function to each element of any axis (specified by the axis parameter, any one or more rows, any one or more columns)
    • Using apply() on a column has the same effect as map(), because a column of a DataFrame object is a Series object
    • Only apply() can be used on multiple columns or rows
    • The apply() method can be used on both Series objects and DataFrame objects
  3. applymap()
    • The first custom function acts on each element of the DataFrame object, and cannot specify rows or columns
    • The applymap() method can only be used on the DataFrame object, there is no applymap() method in the Series object

Guess you like

Origin blog.csdn.net/qq_45458749/article/details/126089319