title: How to loop multiple decay rate in multiple columns in pyspark
body: <p>I try to pass a list in parameter of my function.</p>
  
  <p>My list is composed of different coefficients to be apply to lag numerous columns.</p>
  
  <p>However, I only manage to generate the columns in my dataframe for the first value of my list.</p>
  
  <p>this is my actual result :</p>
  
  <p>"col1", "col2", "col1_0.2", "col2_0.2"</p>
  
  <p>what is expected :</p>
  
  <p>"col1", "col2", "col1_0.2", "col2_0.2", "col1_0.4", "col2_0.4", "col1_0.6", "col2_0.6"</p>
  
  <p>I must have missed a few things in my loop ?</p>
  
  <pre><code>selected_col = col_selector(df, ["col1", "col2"])
  
  
  w = Window.partitionBy("student").orderBy("date")
  coef = (.1,.4,.6)
  
  def custom_coef(col, w, coef):
      for x in coef:
          return sum(
              pow(i, x) * F.lag(F.col(col), i, default=0).over(w)
              for i in range(1)
          ).alias(col +"_"+str(x))
  
  new_df = df.select(
      F.col("*"),
      *[custom_coef(col, w, coef) for col in selected_col]
  )
  </code></pre>
  
  <p>thanks</p>