title: How to deal with a Dataframe with many columns and if statement
body: <p>Here is my problem</p>
  
  <p>You will find below a sample of my DataFrame:</p>
  
  <pre><code>df = pd.DataFrame({'Date':['01/03/2000','01/04/2000','01/05/2000','01/06/2000','01/07/2000','01/08/2000'],
                        'Paul_Score':[3,10,22,32,20,40],
                         'John_Score':[8,42,10,57,3,70]
  
                        })
  
  df['Date']= pd.to_datetime(df['Date'])
  
  df = df.set_index('Date')
  </code></pre>
  
  <p>And I started to work on a loop with an If statement like this:</p>
  
  <pre><code>def test(selection,symbol):
      df_end = (selection*0)
      rolling_mean = selection.rolling(2).mean().fillna(0)
      calendar = pd.Series(df_end.index)
  
      for date in calendar:
          module=1/selection.loc[date,symbol]
          if  selection.loc[date,symbol] &gt; rolling_mean.loc[date,symbol]:
              df_end.loc[date,symbol] = module
  
          else:
              df_end.loc[date,symbol]=0
  
  
      return df_end
  </code></pre>
  
  <p>Then :</p>
  
  <pre><code>test(df,'John_Score')
  </code></pre>
  
  <p>However, my problem is that I don't know how to deal with many columns at the same time, my goal is to try this function on the whole dataframe (for all columns). This sample has only 2 columns but in reality I have 30 columns and I don't know how to do it. </p>
  
  <p>EDIT : </p>
  
  <p>This is what I have with <code>test(df,'John_Score')</code> :</p>
  
  <pre><code>       Paul_Score John_Score
  Date        
  2000-01-03  0   0.125000
  2000-01-04  0   0.023810
  2000-01-05  0   0.000000
  2000-01-06  0   0.017544
  2000-01-07  0   0.000000
  2000-01-08  0   0.014286
  </code></pre>
  
  <p>And this is what I have with <code>test(df,'Paul_Score')</code> :</p>
  
  <pre><code>           Paul_Score John_Score
  Date        
  2000-01-03  0.333333    0
  2000-01-04  0.100000    0
  2000-01-05  0.045455    0
  2000-01-06  0.031250    0
  2000-01-07  0.000000    0
  2000-01-08  0.025000    0
  </code></pre>
  
  <p>And I would like something like that : </p>
  
  <pre><code>          Paul_Score John_Score
  Date        
  2000-01-03  0.333333    0.125000
  2000-01-04  0.100000    0.023810
  2000-01-05  0.045455    0.000000
  2000-01-06  0.031250    0.017544
  2000-01-07  0.000000    0.000000
  2000-01-08  0.025000    0.014286
  </code></pre>
  
  <p>My goal is to check df every day each column and if the value is greater than the value of its rolling mean 2 days then we compute 1/value of df if it is true and 0 if not.</p>
  
  <p>It may have a simpler way but I'm trying to enhance my coding skills on for/if statement and I found that I have difficulties in doing computation on Dataframes with many columns</p>
  
  <p>If you have any idea, you are welcome</p>