title: How do I get all the rows before a specific index in Pandas?
body: <p>I am reading an xlsx file and I want for every row to create columns based on the rows before.</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  
  def get_total(x):
      name = x["NAME"]
      city = x["CITY"]
      index = x.index
      records = df[df.index &lt; index) &amp; (df["NAME"] == name) &amp; (df["CITY"] == city)]
      return records.size[0]
  
  data_filename = "data.xslx"
  df = pd.read_excel(data_filename, na_values=["", " ", "-"])
  df["TOTAL"] = df.apply(lambda x: get_total(x), axis=1)
  </code></pre>
  
  <p>The get_total function is a simple example of what I want to achieve. </p>
  
  <p>I could use <code>df.reset_index(inplace=True)</code> to get the dataframe's index as a column. I think there must be a better way to get the index of a row.</p>