Pythonic Lambda Queries

There is not much literature out there praising the usefulness of lambda functions, so I thought I would make this post about pythonic lambda functions.

Lambda functions originate in lambda calculus as abstractions and application of functions using variable binding and substitution. Such functions take nested form to encapsulate non-specific code with out cluttering code. Because lambda functions are not be bound to any identifier they are also less error-prone.

Given a large data set with the following structure, where dashes represent some data entry such as a string, int or datetime data value, this is often useful in building complex queries of big data.

The code below instantiates lambda functions that will select sub columns from a sequential level column for each given category.

The above statement would return all the data from the table, selecting “Snack” skill as the basis column and all the tutorial levels from “peeling bananas” subskill. As such these little functions can be efficient components, critical to complex dependency heavy programming.

If you like these blog posts or want to comment and or share something do so below and follow py-guy!

Previous Post

Welcome to py-guy! py-guy blog explores science, culture and technology with simple examples and thoughtful discussions. I will list a “preview” link to the previous blog post here once I figure out how to do so and after I’ve written more blog posts.