How to add and reverse a new column according to an id column
<p>This is my first question at stackoverflow and I'm pretty new in the area of programming with python.</p>

<p><a href="http://i.stack.imgur.com/1bKY7.jpg" rel="nofollow">image of what I'm trying to do</a></p>

<p>As you can see in the picture column "id" and "period" are given. It's a csv dataset and I want to add a  new column named "newColumn", where the numbers from "period" are in a reversed order according to their "id values". I hope you understand my problem. </p>

<p>Thank you in advance.</p>

<p>somthing like this:</p>

<pre><code>def f(x, y):
    if x[0] &lt; y[0] or x[0] == y[0] and x[1] &gt; y[1]:
        return -1
    return 1


d = [1, 2, 3, 4, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4]
o = [1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3]
new = zip(o, d)
new.sort(f)
print new
# [(1, 4), (1, 3), (1, 2), (1, 1), (2, 7), (2, 6), (2, 5), (2, 4), (2, 3), (2, 2), (2, 1), (3, 4), (3, 3), (3, 2), (3, 1)]
print zip(*new)[1]
# (4, 3, 2, 1, 7, 6, 5, 4, 3, 2, 1, 4, 3, 2, 1)
</code></pre>

python pandas numpy order reverse