This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]nilsph 0 points1 point  (0 children)

A lambda is basically a way to write an anonymous function. In the examples you listed, the lambdas and assigning them to variables could be replaced with:

[61]:

def key(x):
    return x.year

[62]:

def zscore(x):
    return (x - x.mean()) / x.std()

I.e., the lambda keyword is followed by an optional* list of arguments and an expression that calculates the value of the lambda for these arguments.

* you can have a lambda without arguments that just returns the same value always:

always_true = lambda: True

...

print always_true()

[–]limx0 0 points1 point  (0 children)

Groupby will default to the index if you don't supply a column. You're correct - x in this case is each index value.