I need to collect list of conditional elements to dataframe query, I manage to create it as below:
column = ['TotalCharges', 'gender']
equal = ['>', '==']
condition = [ 20, 'F']
query = ' & '.join(f'{i} {j} {repr(k)}' for i, j, k in zip(column, equal, condition))
So Query output:
TotalCharges > 20 & gender == 'F'
Which is the required and correct ,
Im curious how to achieve same thing using dictionary holds list, meaning
df_query_params = {"column":[],"equal":[],"condition":[]}
df_query_params["column"] = ['TotalCharges', 'gender']
df_query_params["equal"] = [ '>', '==']
df_query_params["condition"] = [20, 'F']
I tried similar approach, with df_query_params.keys()
and also df_query_params.items()
but it doesn't work,
The things that makes me little lost with list comprehension is that i don't know how to "gradually" add more nested elements,