title: Apply a function which takes a DataFrame column as parameter to entire DataFrame
body: <p>I have a function which takes a column of a DataFrame as parameter. I want to apply it to all the columns of a DataFrame without looping.
  I've already looked into the function apply, but I don't understand how to use it in my context.</p>
  <p>Here is my function:</p>
  <pre><code>def shortlong_oneasset(asset):
  
  ret = pd.DataFrame()
  
  n_horizons = len(horizon)
  for i in range(n_horizons):
      r = compute_yields(asset, horizon[i], &quot;horizon&quot;)
           
      r.loc[r[asset.name] &lt; short_threshold, asset.name] = int(-1)
      r.loc[r[asset.name] &gt; long_threshold, asset.name] = int(1)
      r.loc[(r[asset.name] != -1) &amp; (r[asset.name] != 1), asset.name] = 0
      
      
      ret = pd.concat([ret, r], axis = 1)
      
      ret.rename(columns={asset.name: horizon[i]}, inplace = True)
  
  ret = ret.iloc[:,~ret.columns.duplicated()]
  
  #ret = pd.merge_asof(dates.to_frame(), ret, left_on=&quot;Dates&quot;, right_on=&quot;Dates&quot;)
  return ret
  </code></pre>
  <p>The &quot;asset&quot; parameter is a column of a DataFrame, for example:</p>
  <pre><code>shortlong_oneasset(data['column 1'])
  </code></pre>
  <p>Here my DataFrame is named &quot;bonds&quot;. I tried to do:</p>
  <pre><code>test = bonds.apply(lambda x: shortlong_oneassetaverage(x), axis=1)
  </code></pre>
  <p>or</p>
  <pre><code>bonds.apply(shortlong_oneasset)
  </code></pre>
  <p>Can anyone help me with this issue?
  Thanks</p>