the map function is in the form: Map(function, iterable, ...)
Function: Functions, containing two parameters
Iterable: One or more sequences
function functions can be created by themselves, previously using the contents of the CSV file to replace, for example, ' is ' replaced by ' yes ', some Chinese replaced by a digital representation.
Iterable: Generally a list, which can be mapped together by function functions.
PS: note Some minor changes to the Python version: Python2 Returns a list, and Python3 returns an iterator.
The code is as follows:
Import Pandas as Pdpath = R ' C:\Users\dhw\Desktop\work\term paper\home work_10\tree.csv ' #将数据中的中文含义用数据表示def change_the_ Data (PATH): df = pd.read_csv (path) label_list = df[' category ') #存入类别标签 label_list = map (lambda x:[x, ' yes '][x== ') Is '],label_list ' label_list = map (lambda x:[x, ' no '][x== ' no '],label_list) print (list (label_list))
The CSV file category label prints out as:
0 No
1 NO
2 is
3 is
4 No
5 No
6 No
7 is
8 is
9 is
10 is
11 is
12 is
13 is
14 No
After two map conversions: [' No ', ' no ', ' yes ', ' yes ', ' no ', ' no ', ' no ', ' yes ', ' yes ', ' yes ', ' yes ', ' yes ', ' no ']
anonymous functions: Lambda format: Lambda [arg1 [,arg2,..... argn]]:expression Left of colon → The parameter you want to pass colon right → number you want to get (possibly with an expression)
Python function Essay map () function, lambda custom function