Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import functools
- import pandas as pd
- def m1(y, x):
- print(y, x)
- # do something here
- model_data = pd.read_csv("data.csv")
- # filtered column name
- # model_data.columns = ["y", "x1", "x2", ... , "xn"]
- target_cols = [col for col in model_data.columns if "x" in col]
- # filter
- # arget_cols = [*filter(lambda col: if "x" in col, model_data.columns)]
- # 1. for loop
- results = []
- for col in target_cols:
- res = m1(model_data["y"], model_data[col])
- results.append(res)
- # 2. functools.partial with agg
- partial_func = functools.partial(m1, y = model_data["y"])
- results = model_data[target_cols].agg(partial_func)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement