title: Python Pandas Groupby Alternative (Time Series Analysis)
body: <p>Hi guys I'm using pandas to conduct several time series analysis, here is the <code>sample df</code></p>
  <pre><code>data = {'ticker': ['A','A','A','A','A','A','A','B','B','B','B','B','B','B'],
          'high': [10.2,10.5,11,12,15,16,10.2,5,6,6.2,5.3,5.6,7.8,6],
          'low': [10,10.4,10.5,11,14,15,10,4.8,5.5,6,5,5,7.5,5.8]}
  df = pd.DataFrame(data)
  </code></pre>
  <p>I wanna compute 5-day beta for these two stocks with <code>BETA</code> function in <code>TA-Lib</code> and <code>groupby</code> in <code>pandas</code>, here is my code:</p>
  <pre><code>def beta(df):
     df['beta'] = talib.BETA(df.high, df.low, timeperiod=5)
     df['beta_above_1'] = np.where(df.beta &gt; float(1), True, False)
  return df
  df = df.groupby(['ticker']).apply(beta)
  </code></pre>
  <p>It works and return me this result:</p>
  <pre><code>    ticker high  low        beta     beta_above_1
  0       A  10.2  10.0       NaN         False
  1       A  10.5  10.4       NaN         False
  2       A  11.0  10.5       NaN         False
  3       A  12.0  11.0       NaN         False
  4       A  15.0  14.0       NaN         False
  5       A  16.0  15.0  1.151536          True
  6       A  10.2  10.0  0.952395         False
  7       B   5.0   4.8       NaN         False
  8       B   6.0   5.5       NaN         False
  9       B   6.2   6.0       NaN         False
  10      B   5.3   5.0       NaN         False
  11      B   5.6   5.0       NaN         False
  12      B   7.8   7.5  1.182857          True
  13      B   6.0   5.8  1.177912          True
  </code></pre>
  <p>However, the required time is a bit long while I apply this approach to over million rows dataframe. I've researched about <strong>vectorization</strong> to speed up the calculation but I got no idea to improve it.</p>
  <p>May I know if there is <strong>other faster ways</strong> to conduct the same analysis? Thanks a lot!</p>