So I have a question that I've searched high and low for, and that I can't imagine is unique, but I haven't seen definitively answered.
What I'd like to do is a create a suite of very simple filters, and then allow the user to compose them in any way possible. This is what you see on any website when you filter clothing by, say, size and type and color and price. My data is in a Pandas dataframe (but presumably that's easily interoperable with SQL).
Simple, right?
The most import and thing for me is ease of syntax to the end user. Ideally, I'd like to get the user something as close to:
my_closet = DataFrame()
wardrobe = my_closet.is_shirt().size("large").is_red().long_sleeve(True)
To that end, I've seen three ways of doing this:
1). Pandas Pipes.
def get_color(df, color):
return df[df['color'] == color]
def is_shirt(df):
return df[df['shirt'] == True]
(poll.pipe(is_shirt)
.pipe(get_color, color=red)
)
This isn't the greatest. Too many parens, too much typing.
- Functional Python programming (i.e. "pure" Python)
I'm not super familiar with this
- Send everything to SQL and use something like sqlalchemy (and send it back to a DF)
4* Just found about a masks...define a number of functions that are masks (or masks that are functions?) and let the use play with them?
Again, the number one concern is the simplicity of the syntax for the end user.
Anyone have any ideas or suggestions for how to go about doing this?