Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can also use numpy for this. Assuming you have:</p> <pre><code>dates = numpy.array([datetime(2012,02,03,12,00,00), datetime(2012,02,03,15,00,00), datetime(2012,02,03,13,00,00)]) values = numpy.array([[1, 1], [3, 3], [2, 2]]) </code></pre> <p>You can do at first:</p> <pre><code>unified = numpy.concatenate((dates.reshape(len(dates), 1), values), axis=1) </code></pre> <p>This will merge your two list, which considering what you want should be a better suited way to hold your data anyway. So now you have:</p> <pre><code>unified = array([[2012-02-03 12:00:00, 1, 1], [2012-02-03 15:00:00, 3, 3], [2012-02-03 13:00:00, 2, 2]], dtype=object) </code></pre> <p>Now you can do:</p> <pre><code>unified = numpy.sort(unified, axis=0) </code></pre> <p>This will sort after date. Now if you still want just the separate lists you can get them with: </p> <pre><code>unified[:, 0] &gt;&gt;&gt; array([2012-02-03 12:00:00, 2012-02-03 13:00:00, 2012-02-03 15:00:00], dtype=object) unified[:, 1:] &gt;&gt;&gt; array([[1, 1], [2, 2], [3, 3]], dtype=object) </code></pre> <p><strong>EDIT</strong> after your comment Ok now that I fully understand what you want you can achieve that by replacing</p> <pre><code> unified = numpy.sort(unified, axis=0) </code></pre> <p>with:</p> <pre><code> unified = numpy.array(sorted(unified, key= lambda x: x[0])) </code></pre> <p><strong>EDIT</strong></p> <p>have you tried what I just suggested? In my terminal:</p> <pre><code> unified = numpy.array([[datetime(2012,02,03,12,00,00), 4, 1],[datetime(2012,02,03,15,00,00), 5, 2],[datetime(2012,02,03,13,00,00), 2, 1]], dtype=object) &gt;&gt;&gt; unified array([[2012-02-03 12:00:00, 4, 1], [2012-02-03 15:00:00, 5, 2], [2012-02-03 13:00:00, 2, 1]], dtype=object) &gt;&gt;&gt; unified = numpy.array(sorted(unified, key=lambda x: x[0])) &gt;&gt;&gt; unified array([[2012-02-03 12:00:00, 4, 1], [2012-02-03 13:00:00, 2, 1], [2012-02-03 15:00:00, 5, 2]], dtype=object) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload