Note that there are some explanatory texts on larger screens.

plurals
  1. POconstruct and order a list of tuples
    primarykey
    data
    text
    <p>Data format in a text,</p> <pre><code>2010-04-16,9:15:00,3450,3488,3450,3470 </code></pre> <p>Parse the text,</p> <pre><code>Utuple = collections.namedtuple('Utuple', 'DT,OpenPrice,ClosePrice,HighPrice,LowPrice') stats = collections.Counter() for line in data.readlines(): cols = line.split(',') Date = cols[0] d = Date.split('-') Time = cols[1] t = Time.split(':') DT = datetime(int(d[0]), int(d[1]), int(d[2]), int(t[0]), int(t[1]), int(t[2])) DT = mdates.date2num(DT) OpenPrice = float(cols[2]) HighPrice = float(cols[3]) LowPrice = float(cols[4]) ClosePrice = float(cols[5]) stats[DT] = Utuple(DT,OpenPrice,ClosePrice,HighPrice,LowPrice) </code></pre> <p>I want to get a list of tuples to fit the format of <code>candlesticks</code> in matplotlib.finance, which is expected to be</p> <pre><code> D = [(datetime.datetime(2010, 4, 16, 9, 30), 311, 332, 344, 311), (datetime.datetime(2010, 4, 16, 9, 31), 312, 332, 344, 311), (datetime.datetime(2010, 4, 16, 9, 32), 323, 332, 344, 320), (datetime.datetime(2010, 4, 16, 13, 0), 331, 332, 344, 330), (datetime.datetime(2010, 4, 16, 13, 1), 335, 342, 348, 333)] </code></pre> <p>and I did:</p> <pre><code>formated_data = [] for time, index in stats.items(): formated_data.append(tuple(index)) </code></pre> <p>I want to keep this order. But in <code>formated_data</code>, it turns out that the lines with <code>13</code> in the fourth column in datetime.datetime end up in the front of those with <code>9</code>. How to keep the order of the tuples <code>by the order that I save them</code> or by <code>the value of the number (9 &lt; 13)</code>?</p>
    singulars
    1. This table or related slice is empty.
    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. 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