Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is what I think you're trying to accomplish based on your edit: for every date in your CSV file, group the date along with a list of prices for each item with a signal of "S".</p> <p>You didn't include any sample data in your question, so I made a test one that I hope matches the format you described:</p> <pre><code>12/28/2012,1:30,10.00,"foo","S" 12/28/2012,2:15,11.00,"bar","N" 12/28/2012,3:00,12.00,"baz","S" 12/28/2012,4:45,13.00,"fibble","N" 12/28/2012,5:30,14.00,"whatsit","S" 12/28/2012,6:15,15.00,"bobs","N" 12/28/2012,7:00,16.00,"widgets","S" 12/28/2012,7:45,17.00,"weevils","N" 12/28/2012,8:30,18.00,"badger","S" 12/28/2012,9:15,19.00,"moose","S" 11/29/2012,1:30,10.00,"foo","N" 11/29/2012,2:15,11.00,"bar","N" 11/29/2012,3:00,12.00,"baz","S" 11/29/2012,4:45,13.00,"fibble","N" 11/29/2012,5:30,14.00,"whatsit","N" 11/29/2012,6:15,15.00,"bobs","N" 11/29/2012,7:00,16.00,"widgets","S" 11/29/2012,7:45,17.00,"weevils","N" 11/29/2012,8:30,18.00,"badger","N" 11/29/2012,9:15,19.00,"moose","N" 12/29/2012,1:30,10.00,"foo","N" 12/29/2012,2:15,11.00,"bar","N" 12/29/2012,3:00,12.00,"baz","S" 12/29/2012,4:45,13.00,"fibble","N" 12/29/2012,5:30,14.00,"whatsit","N" 12/29/2012,6:15,15.00,"bobs","N" 12/29/2012,7:00,16.00,"widgets","S" 12/29/2012,7:45,17.00,"weevils","N" 12/29/2012,8:30,18.00,"badger","N" 12/29/2012,9:15,19.00,"moose","N" 8/9/2008,1:30,10.00,"foo","N" 8/9/2008,2:15,11.00,"bar","N" 8/9/2008,3:00,12.00,"baz","S" 8/9/2008,4:45,13.00,"fibble","N" 8/9/2008,5:30,14.00,"whatsit","N" 8/9/2008,6:15,15.00,"bobs","N" 8/9/2008,7:00,16.00,"widgets","S" 8/9/2008,7:45,17.00,"weevils","N" 8/9/2008,8:30,18.00,"badger","N" 8/9/2008,9:15,19.00,"moose","N" </code></pre> <p>And here's a method using Python 2.7 and built-in libraries to group it in the way it sounds like you want:</p> <pre><code>import csv import itertools import time from collections import OrderedDict with open("sample.csv", "r") as file: reader = csv.DictReader(file, fieldnames=["date", "time", "price", "mag", "signal"]) # Reduce the size of the data set by filtering out the non-"S" rows. filterFunc = lambda row: row["signal"] == "S" filteredData = itertools.ifilter(filterFunc, reader) # Sort by date so we can use the groupby function. dateKeyFunc = lambda row: time.strptime(row["date"], r"%m/%d/%Y") sortedData = sorted(filteredData, key=dateKeyFunc) # Group by date: create a new dictionary of date to a list of prices. datePrices = OrderedDict((date, [row["price"] for row in rows]) for date, rows in itertools.groupby(sortedData, dateKeyFunc)) for date, prices in datePrices.iteritems(): print "{0}: {1}".format(time.strftime(r"%m/%d/%Y", date), ", ".join(str(price) for price in prices)) &gt;&gt;&gt; 08/09/2008: 12.00, 16.00 &gt;&gt;&gt; 11/29/2012: 12.00, 16.00 &gt;&gt;&gt; 12/28/2012: 10.00, 12.00, 14.00, 16.00, 18.00, 19.00 &gt;&gt;&gt; 12/29/2012: 12.00, 16.00 </code></pre> <p>The type conversions are up to you, since you may be using other libraries to do your CSV reading, but that should hopefully get you started -- and take careful note of @DSM's comment about import *.</p>
    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. 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.
 

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