Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can hack something together using the <code>csv</code> module and <a href="http://docs.python.org/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehensions</a>:</p> <pre><code>import csv reader = csv.reader(open('data.csv', 'r')) rows = [row for row in reader] # select * from data where first column &lt; 4 # this won't actually work as-is! see the edit below [row for row in rows if row[0] &lt; 4] # select * from data where second column &gt;= third column [row for row in rows if row[1] &gt;= row[2]] # select columns 1 and 3 from data where first column is "mykey" [[row[0], row[2]] for row in rows if row[0] == "mykey"] </code></pre> <p>You can probably do some even more impressive things with Python’s <a href="http://docs.python.org/tutorial/datastructures.html#functional-programming-tools" rel="nofollow">functional programming tools</a>, although if you’re not already familiar with FP it’s probably too big of a topic to learn just for this ;-)</p> <hr> <p><strong>Edit:</strong> A couple more tips:</p> <ul> <li><p>If you’re only going to perform one “query” per script, you can cut out the intermediate storage of the data (<code>rows</code> in my example):</p> <pre><code>import csv reader = csv.reader(open('data.csv', 'r')) result = [row for row in reader if row[0] == "banana"] </code></pre></li> <li><p>The csv reader generates all of its output as text, so if you want to treat one column as e.g. an integer you’ll have to do that yourself. For example, if your second and third columns are integers,</p> <pre><code>import csv reader = csv.reader(open('data.csv', 'r')) rows = [[row[0], int(row[1]), int(row[2])] for row in reader] # perform a "select" on rows now </code></pre> <p>(This means that my first example above won’t actually work as-is.) If <em>all</em> of your columns are integers then you can invoke the functional <code>map</code> function:</p> <pre><code>import csv reader = csv.reader(open('data.csv', 'r')) rows = [map(int, row) for row in reader] </code></pre></li> </ul>
    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.
    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