Hi @leb_dev,
I spent a little time building out my concept. Check out the code here.
The filter fields and the filter input fields are specified declaratively. The filter query is dynamically constructed as you select filter fields and enter field values. The query can then be applied to the Pandas data frame. The neat thing about this solution is there is not one “if” statement in sight to control the filtering logic, and you can adjust the filters UI through the declarative specification. The rest of the code just works.
To use this sample gist for something serious, you should encapsulate the functions better and ensure you test it with very large data frames.
The code is generic enough that you could easily replace the Pandas data persistence with a proper database. The Pandas method pd.DataFrame.query()
could be replaced with something like db.execute_query()
. The query builder would construct a SQL query instead of a Pandas query.
HTH,
Arvindra