Advertisement
Guest User

PTT #1YtLdH-x (Python)

a guest
Jul 26th, 2022
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. import functools
  2. import pandas as pd
  3.  
  4.  
  5. def m1(y, x):
  6.     print(y, x)
  7.     # do something here
  8.    
  9. model_data = pd.read_csv("data.csv")
  10. # filtered column name
  11. # model_data.columns = ["y", "x1", "x2", ... , "xn"]
  12. target_cols = [col for col in model_data.columns if "x" in col]
  13. # filter
  14. # arget_cols = [*filter(lambda col: if "x" in col, model_data.columns)]
  15.  
  16. # 1. for loop
  17. results = []
  18. for col in target_cols:
  19.     res = m1(model_data["y"], model_data[col])
  20.     results.append(res)
  21.    
  22.  
  23. # 2. functools.partial with agg
  24. partial_func = functools.partial(m1, y = model_data["y"])
  25. results = model_data[target_cols].agg(partial_func)
  26.  
  27.  
  28.  
  29.    
  30.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement