Python Beginners Alternate Knowledge point

Source: Internet
Author: User
Tags iterable

python keyword Parameters


the usage function of the Python apply function is in the form: Apply (Func,*args,**kwargs)

Use: When the parameter of a function exists in a tuple or a dictionary, it is used to call the function indirectly, either side-or the dictionary parameters are passed to the parameters in order.

Parsing: args is a tuple that contains positional arguments that are passed according to the parameters required by the function. is not very awkward, meaning that if a function of the function position is a (a=1,b=2), then the tuple must be strictly according to the position of this parameter to pass (a=3,b=4), and not be (b =4,A=3) in this order
Kwargs is a dictionary that contains keyword parameters, where args if it is not passed and Kwargs needs to be passed, the args must be left blank

The return value of the Apply is the return value of the function Func function

def function (a,b): print (a,b) apply (function, (' good ', ' better ') apply (function, (2,3+6)) output result:

(' good ', ' better ')

(2, 9)


Python filter () function Grammar

The following is the syntax for the filter () method:

Filter (function, iterable)
ParametersFunction---------judgment functions. Iterable--Can iterate over objects. return value

Returns the list. python-lambda expression

Lambda expressions are usually used in situations where a function is needed, but you do not want to bother naming a function, which means an anonymous function.

The content of the anonymous function that the lambda represents should be simple, and if it's complicated, simply redefine a function, and using a lambda is a bit too stubborn.

A lambda is used to define an anonymous function, and if you have to bind a name to it, it will be a little superfluous, usually directly using a lambda function. As shown below:

Add = lambda x, y:x+y
Add (1,2)  # results 3
Python axis

The highest answer to the vote reveals the nature of the problem:

In fact, the problem is that axis has a problem, Df.mean is actually taking the mean value of all the columns on each row, rather than preserving the average of each column. Perhaps the simple thing to remember is that the axis=0 represents the cross line (down), while the Axis=1 represents the cross column (across) as an adverb of the method action (translator note)

In other words: Use a value of 0 to indicate that a method is executed along each column or row label \ Index value by using a value of 1 to represent the mode of execution along each row or column label.

The following figure represents the meaning of axis 0 and 1 o'clock in Dataframe, respectively:

Axis parameter Action Direction diagram

Also, remember that pandas maintains NumPy's usage of the keyword axis, which is explained in the Glossary of NumPy libraries:

An axis is used to define a property that is more than one dimension, and the two-dimensional data has two axes: the No. 0 axis goes down vertically along the line, and the 1th axis extends horizontally along the direction of the column.

So the first column in the question Df.mean (Axis=1) represents the average in the horizontal direction of the column, while the second column df.drop (name, Axis=1) represents the column labels that correspond to the name in the horizontal direction.



Related Article

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.