apply(func [, args [, kwargs ]])
Function is used when a function parameter already exists in a tuple or dictionary , Call the function indirectly .args Is a tuple containing the positional arguments to be provided to the function . If omitted args, let
No parameter is passed ,kwargs Is a dictionary containing keyword parameters . in brief apply() The return value of is func() Return value of ,apply() The element parameters of are ordered , The order of elements must be the same as func() The order of formal parameters is consistent , And map The difference is that the former aims at column, The latter is for elements

lambda It's an anonymous function , That is, it is no longer used def The form of , The script can be simplified , How to make the structure not redundant
a = lambda x : x + 1 a(10) 11
A combination of the two can do a lot of things , such as split stay series Many functions are not available in the system , and index You can do it

For example, there is a string of data as follows , To split into total numbers , Correct number , Accuracy , This can be done

96%(1368608/1412722)
97%(1389916/1427922)
97%(1338695/1373803)
96%(1691941/1745196)
95%(1878802/1971608)
97%(944218/968845)
96%(1294939/1336576)
import pandas as pd # Mr. Cheng is a teacher dataframe d = {"col1" : ["96%(1368608/1412722)",
"97%(1389916/1427922)", "97%(1338695/1373803)", "96%(1691941/1745196)",
"95%(1878802/1971608)", "97%(944218/968845)", "96%(1294939/1336576)"]} df1 =
pd.DataFrame(d) # Total recognition rate of original text segmentation , use apply + Anonymous function #lambda Function means select x Sequence value of , such as x[6:9]
#index The function converts the current character position to the number of digits in the position #-1 It's the last one df1[' Correct number '] = df1.iloc[:,0].apply(lambda
x : x[x.index('(') + 1 : x.index('/')]) df1[' total '] = df1.iloc[:,0].apply(lambda
x : x[x.index('/') + 1 : -1]) df1[' Accuracy '] = df1.iloc[:,0].apply(lambda x :
x[:x.index('(')]) df1

Technology