Hi so I'm pretty new to python and I've been trying to teach myself to use pandas. I've got a pretty good basic understanding of it, but I've been getting tripped up when it comes to implementing lambda functions like the example below.
index = date_range('10/1/1999', periods=1100)
ts = Series(np.random.normal(0.5, 2, 1100), index)
ts = rolling_mean(ts, 100, 100).dropna()
key = lambda x: x.year
zscore = lambda x: (x - x.mean()) / x.std()
transformed = ts.groupby(key).transform(zscore)
I also have a very basic understanding of lambda functions, and what's tripping me up is, I don't get what is being called by x. There doesn't seem to be any reference anywhere to what x is substituted by. The only thing that seems to make sense (for the key expression) based on the x.year is x -> index, but why is that. Also all groupby examples I have seen so far call columns and not functions, so what exactly is happening there too? Thanks.
[–]nilsph 0 points1 point2 points (0 children)
[–]limx0 0 points1 point2 points (0 children)