Determining Increasing or Decreasing Values based on Sequential Rows Per Key
<p>I have a dataset of 90,000 records. These 90,000 records belong to about 3,000 unique Keys. For each Key, the values are ordered starting with an ItemNumber of 1 and going up to 'n'. </p>

<p>For each Key 1 to n, I want to compare the 2nd row to the first row, the 3rd row to the 2nd row and so on. A sample of my table is given below with some values populated as an example of what's expected.</p>

<p>I have a column for milepost values and want to know whether the values are ascending or descending between consecutive records. </p>

<p>Example image found at URL: <a href="http://i.imgur.com/i1nuAK9.png" rel="nofollow">http://i.imgur.com/i1nuAK9.png</a> since I am too new to embed a picture.</p>

<p>I am very new to python and am having trouble getting started. Even if I can compare "ProjectKey A, ItemNum 2" to "ProjectKey A, ItemNum 1" to know that it's ascending what can I compare the 1st record to? I am having trouble determining which direction to parse. </p>

<p>Any help would be greatly appreciated!</p>

<p>EDIT: 
Snippet as a csv</p>

<p>ProjectKey,ItemNum,BMP,Direction
A,1,0.2,_
A,2,1.7,_
A,3,2.5,_
A,4,5,_
A,5,9,_
A,6,12,_
B,1,25,_
B,2,24.2,_
B,3,21.7,_
B,4,20.3,_
C,1,3,_
C,2,4,_
C,3,5,_
C,4,6,_
C,5,5,_
C,6,4,_
C,7,3,_
C,8,2,_</p>

<p>Once you have transferred the data to text, you could use a set of lists and a for loop to parse through and compare:</p>

<pre><code>keylistA = [0.2, 1.7, 2.5, 5, 9, 12]
listAdirection = ['(start)']

for i in range(0, len(keylistA)):
    if keylistA[i] &gt; keylistA[i+1]:
        listAdirection.append('DESC')
    elif keylistA[i] &lt; keylistA[i+1]:
        listAdirection.append('ASC')
    else:
        listAdirection.append('SAME')
</code></pre>

<p>This would give you some lists like this:</p>

<pre><code>listAdirection = ['(start)', 'ASC', 'ASC', 'ASC', 'ASC', 'ASC']
</code></pre>

<p>You could have the lists saved in a nested list format, or using some sort of dictionary setup.  Of course, this is all highly dependent on how you choose to export the data from those columns into text.</p>

python list direction