title: What's the fastest way to get the standard deviations iterated over rows with shrinking population?
body: <p>I am trying to calculate the std deviations for specific categories (CAT1, CAT2, CAT3) of 'PD Percent' data and want to know how the std deviation changes as the expiration date approaches.
  What I tried doing is iterating over every row for each category and calculate the std devs for the remaining days in the category series. For example, Cat1 starts with DTE 50 so I would perform a Std Dev from 50 to 0 DTE notwithstanding the last day (ODTE). Basically, the std deviation is calculated on a shrinking population and am looking for any help on how to achieve this faster than iteration if possible.</p>
  <pre><code>for category in category_list:
      for exp_date in exp_dates_list:    
          min_dte = df[df['category'] == category].loc[df['Expiration Date'] == exp_date]['DTE'].min()
              if min_dte == 0:
                  dte_list = list(df[df['category'] == category].loc[df['Expiration Date'] == exp_date]['DTE'])
                  for dte in dte_list:
                      std_dev = df[(df['category'] == category)  &amp; (df['Expiration Date'] == exp_date) &amp; (df['DTE'] &lt;= dte) ]['Price Delta Percent'].std()
                      df.loc[(df['category'] == category)  &amp; (df['Expiration Date'] == exp_date) &amp; (df['DTE'] == dte), 'PDP StdDev'] = std_dev
  </code></pre>
  <p>I just started learning Pandas last month and am still learning so am asking for any tips on making this faster as I'm completely swamped by the slow iteration. Pasted below is the data in case you'd like to work on your own. Thanks for the assist!</p>
  <p>Raw Data: <a href="https://pastebin.com/raw/JZwvdt1j" rel="nofollow noreferrer">Pastebin CSV Data STD DEV ROW ITERATION</a></p>