title: RuntimeWarning: invalid value encountered in longlong_scalars
body: <h1>What I'm trying to do</h1>
  
  <p>I want to report the weekly rejection rate for multiple users. I use a for loop to go through a monthly dataset to get the numbers for every user. The final dataframe, <code>rates</code>, should look something like:</p>
  
  <p><a href="https://i.stack.imgur.com/yzV7W.png" rel="noreferrer">The end product, <code>rates</code></a></p>
  
  <h1>Description</h1>
  
  <p>I have an initial dataframe (<code>numbers</code>), that contains only the ACCEPT, REJECT and REVIEW numbers, where I added these rows and columns:</p>
  
  <ul>
  <li><strong>Rows</strong>: Grand Total, Rejection Rate</li>
  <li><strong>Columns</strong>: Grand Total</li>
  </ul>
  
  <p>Here's how <code>numbers</code> look like:</p>
  
  <pre><code>|---|--------|--------|--------|--------|-------------|
  |   | Week 1 | Week 2 | Week 3 | Week 4 | Grand Total | 
  |---|--------|--------|--------|--------|-------------|
  | 0 |  994   |  699   |  529   |   877  |     3099    | 
  |---|--------|--------|--------|--------|-------------|
  | 1 |   27   |   7    |    8   |   13   |      55     |
  |---|--------|--------|--------|--------|-------------|
  | 2 |  100   |   86   |   64   |   107  |      357    |
  |---|--------|--------|--------|--------|-------------|
  | 3 |  1121  |  792   |  601   |  997   |    3511     |
  |---|--------|--------|--------|--------|-------------|
  </code></pre>
  
  <p>The indexes represent the following values:</p>
  
  <ul>
  <li>0 - ACCEPT</li>
  <li>1 - REJECT</li>
  <li>2 - REVIEW</li>
  <li>3 - TOTAL (Accept+Reject+Review)</li>
  </ul>
  
  <p>I wrote 2 pre-defined functions:</p>
  
  <ol>
  <li><code>get_decline_rates(df)</code>: The get the decline rates by week in the <code>numbers</code> dataframe.</li>
  <li><code>copy(empty_df, data)</code>: To transfer all data to a new dataframe with "double" headers (for reporting purposes).</li>
  </ol>
  
  <p>Here's my code where I add rows and columns to <code>numbers</code>, then re-format it:</p>
  
  <pre><code># Adding "Grand Total" column and rows
  totals = numbers.sum(axis=0) # column sum
  numbers = numbers.append(totals, ignore_index=True)
  grand_total = numbers.sum(axis=1) # row sum
  numbers.insert(len(numbers.columns), "Grand Total", grand_total)
  
  # Adding "Rejection Rate" and re-indexing numbers
  decline_rates = get_decline_rates(numbers)
  numbers = numbers.append(decline_rates, ignore_index=True)
  numbers.index = ["ACCEPT","REJECT","REVIEW","Grand Total","Rejection Rate"]
  
  # Creating a new df with report format requirements 
  final = pd.DataFrame(0, columns=numbers.columns, index=["User A"]+list(numbers.index))
  final.ix["User A",:] = final.columns
  
  # Copying data from numbers to newly formatted df
  copy(final,numbers) 
  
  # Append final df of this user to the final dataframe
  rates = rates.append(final)
  </code></pre>
  
  <p>I'm using <strong>Python 3.5.2</strong> and <strong>Pandas 0.19.2</strong>. If it helps, here's how the initial dataset looks like:</p>
  
  <p><a href="https://i.stack.imgur.com/MiD04.png" rel="noreferrer">Data format</a></p>
  
  <p>I do a resampling on the date column to get the data by week. </p>
  
  <h1>What's going wrong</h1>
  
  <p>Here's the funny part - the code runs fine and I get all the required information in <code>rates</code>. However, I'm seeing this warning message:</p>
  
  <blockquote>
    <p>RuntimeWarning: invalid value encountered in longlong_scalars</p>
  </blockquote>
  
  <p>If i break down the code and run it line by line, this message does not appear. Even the message looks weird (what does <em>longlong_scalars</em> even mean?) Does anyone know what this warning message mean, and what's causing it? </p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I just ran a similar script that takes in exactly the same input and produces a similar output (except I get daily rejection rates instead of weekly). I get the same Runtime warning, except more information is given:</p>
  
  <blockquote>
    <p>RuntimeWarning: invalid value encountered in longlong_scalars</p>
    
    <p>rej_rate = str(int(round((col.ix[1 ]/col.ix[3 ])*100))) + "%"</p>
  </blockquote>
  
  <p>I suspect something must have gone wrong when I was trying to calculate the decline rates with my pre-defined function, <code>get_decline_rates(df)</code>. Could it be due to the dtype of the values? All columns on the input df, <code>numbers</code>, are <code>int64</code>. </p>
  
  <p>Here's the code for my pre-defined function (the input, <code>numbers</code>, can be found under <strong>Description</strong>):</p>
  
  <pre><code># Description: Get rejection rates for all weeks.
  # Parameters: Pandas Dataframe with ACCEPT, REJECT, REVIEW count by week.
  # Output: Pandas Series with rejection rates for all days in input df.
  def get_decline_rates(df):
      decline_rates = []
      for i in range(len(df.columns)):
          col = df.ix[:,i]
  
          try:
              rej_rate = str(int(round((col[1]/col[3])*100))) + "%"
          except ValueError:
              rej_rate = "0%"
  
          decline_rates.append(rej_rate)
  
      return pd.Series(decline_rates, index=df.columns)
  </code></pre>