How to use apply (), map () and applymap () of python
This article mainly explains the "python apply (), map (), applymap () how to use", the article explains the content is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "python apply (), map (), applymap () how to use it!"
In the data analysis of python, the custom operation of batch data can be easily realized by using apply (), map () and applymap (). Its usage is summarized as follows.
Function usage apply () is used to manipulate data in DataFrame by row or column. Map () is used to operate on every data in Series. Applymap () is used to manipulate every data in DataFrame. Example apply ()
Apply () is used to manipulate data in DataFrame by row or column.
Import pandas as pddata = [[110,120,110], [130,120,130]] columns= ['Chinese', 'mathematics', 'English'] df = pd.DataFrame (data=data, columns=columns) print (df) print ("=") print (lambda x: x.sum (), axis=1))
Where axis=1 stands for line alignment. An axis of 0 indicates a column alignment.
Map ()
Map () is used to manipulate every data in the Series.
Import pandas as pds1 = pd.Series ([11, 22, 33, 44, 55]) print (S1) print ("=") print (s1.map (lambda x: str (x) applymap
Applymap () is used for every data operation on DataFrame.
Manipulate every piece of data in DataFrame.
Take keeping two decimal places for each piece of data as an example:
Import pandas as pddata = [[110,120,110], [130,120,130]] columns= ['Chinese', 'mathematics', 'English'] df = pd.DataFrame (data=data, columns=columns) print (df) print ("=") print (df.applymap (lambda x:'% .2f'% x))
Thank you for your reading, the above is the "python apply (), map (), applymap () how to use" the content, after the study of this article, I believe you on python apply (), map (), applymap () how to use this problem has a deeper understanding, the specific use of the situation also needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!