I received a wonderful lambda function from a user a while ago.
actresses_modified['Winner_Count'] = actresses_modified.apply(lambda x: actresses_modified.Name.value_counts()[x.Name], axis=1)
The data frame to which it is applied looks like this:
Year Award Winner Name
2 1928 Best Actress 0.0 Louise Dresser
3 1928 Best Actress 1.0 Janet Gaynor
4 1928 Best Actress 0.0 Gloria Swanson
40 1929 Best Actress 0.0 Ruth Chatterton
41 1929 Best Actress 0.0 Betty Compson
The problem is I have forgotten how it works (I had to step away from this "for fun" project) and, more specifically, exactly what is going on with [x.Name]
.
The line actresses_modified.Name.value_counts()
by itself gives me the count of all actress names in the data frame. What does [x.Name] mean in english, how does it manage to tally up all of the 1s next to each person's name in the data frame's Winner column, and return a correct tally of the total number of wins? Of equal importance, does this type of syntax have a name? My google searches turned up nada.
Any thoughts would be appreciated?