title: How to apply a function to each column of a pivot table in pandas?
body: <p>Code:</p>
  
  <pre><code>df = pd.read_csv("example.csv", parse_dates=['ds'])
  df2 = df.set_index(['ds', 'city']).unstack('city')
  rm = pd.rolling_mean(df2, 3)
  sd = pd.rolling_std(df2,3)
  </code></pre>
  
  <p>df2 output:</p>
  
  <p><a href="https://i.stack.imgur.com/tHfnc.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tHfnc.png" alt="enter image description here"></a></p>
  
  <p>What I want: I want to be able to see whether for each city, for each date, if the number is greater than 1 std dev away from the mean of bookings for that city. For ex pseudocode:</p>
  
  <pre><code>for each (city column) 
  for each (date)
  see whether the (number of bookings) - (same date and city rolling mean) &gt; (same date and city std dev)
  print that date and city and number of bookings
  </code></pre>
  
  <p>What the problem is: I'm having trouble trying to figure out how to access the data I need from each of the data frames to do so. The parts of the pseudocode in parenthesis is what I need help figuring out.</p>
  
  <p>What I tried:</p>
  
  <p>df2['city']
  list(df2)</p>
  
  <p>Both give me errors.</p>
  
  <p>df2[1:2]</p>
  
  <p>Splicing works, but I feel like thats not the best way to access it.</p>