Skip to content
Advertisement

Most efficient way of applying a function based on condition

Suppose we have a master dictionary master_dict = {"a": df1, "b": df2, "c": df3}. Now suppose we have a list called condition_list. Suppose func is a function that returns a new dictionary that has the original keys of master_dict along with potentially new keys.

What is the best way to get the below code to work when the length of condition_list is greater than 2:

JavaScript

Advertisement

Answer

You need to ask clearly. Declare input and output. And try to make a demo code. Anyway, use a loop.

JavaScript

If the “df” is a dataframe of pandas, the conditions can be applied at once. Search “select dataframe with multiple conditions”

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement