Python function Essay map () function, lambda custom function

Source: Internet
Author: User
Tags iterable

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.