<div dir="ltr"><div><font face="monospace, monospace">This is trivial in pandas. a simple groupby.</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">In [6]: data = [[ 'a', 27, 14.5 ],['b', 12, 99.0],['a', 17, 100.3], ['b', 12, -329.0]]</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">In [7]: df = DataFrame(data, columns=list('ABC'))</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">In [8]: df</font></div><div><font face="monospace, monospace">Out[8]: </font></div><div><font face="monospace, monospace"> A B C</font></div><div><font face="monospace, monospace">0 a 27 14.5</font></div><div><font face="monospace, monospace">1 b 12 99.0</font></div><div><font face="monospace, monospace">2 a 17 100.3</font></div><div><font face="monospace, monospace">3 b 12 -329.0</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">In [9]: df.groupby('A').first()</font></div><div><font face="monospace, monospace">Out[9]: </font></div><div><font face="monospace, monospace"> B C</font></div><div><font face="monospace, monospace">A </font></div><div><font face="monospace, monospace">a 27 14.5</font></div><div><font face="monospace, monospace">b 12 99.0</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">In [10]: df.groupby('A').last()</font></div><div><font face="monospace, monospace">Out[10]: </font></div><div><font face="monospace, monospace"> B C</font></div><div><font face="monospace, monospace">A </font></div><div><font face="monospace, monospace">a 17 100.3</font></div><div><font face="monospace, monospace">b 12 -329.0</font></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 4, 2016 at 7:27 PM, Skip Montanaro <span dir="ltr"><<a href="mailto:skip.montanaro@gmail.com" target="_blank">skip.montanaro@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">> Any way that you can make your keys numeric? Then you can run np.diff on<br>
> that first column, and use the indices of nonzero entries (np.flatnonzero)<br>
> to know where values change. With a +1/-1 offset (that I am too lazy to<br>
> figure out right now ;) you can then index into the original rows to get<br>
> either the first or last occurrence of each run.<br>
<br>
</span>I'll give it some thought, but one of the elements of the key is definitely<br>
a (short, < six characters) string. Hashing it probably wouldn't work, too<br>
great a chance for collisions.<br>
<span class="HOEnZb"><font color="#888888"><br>
S<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@scipy.org">NumPy-Discussion@scipy.org</a><br>
<a href="https://mail.scipy.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.scipy.org/mailman/listinfo/numpy-discussion</a><br>
</div></div></blockquote></div><br></div>