2

I am trying to query from a database and I've tried to lookup the right way to format an SoQL string but I am failing. I try the following:

from __future__ import division, print_function
from sodapy import Socrata
import pandas as pd
import numpy as np


client = Socrata("data.cityofchicago.org", None)

df = client.get("kkgn-a2j4", query="WHERE traffic > -1")

and receive an error that it Could not parse SoQL query "WHERE traffic > -1" at line 1 character 1. If I do the following, however, it works:

from __future__ import division, print_function
from sodapy import Socrata
import pandas as pd
import numpy as np


client = Socrata("data.cityofchicago.org", None)

df = client.get("kkgn-a2j4", where="traffic > -1")

But I want to know how to get the query argument to work so I can use more complex queries. Specifically, I want to try to query when traffic > -1 and BETWEEN '2013-01-19T23:50:32.000' AND '2014-12-14T23:50:32.000'.

jtorca
  • 1,531
  • 2
  • 17
  • 31

1 Answers1

2

You can use the sodapy where parameter ($where in SoQl) to combine multiple filters, just use AND to combine them:

traffic > -1 AND last_update BETWEEN '2013-01-19T23:50:32.000' AND '2014-12-14T23:50:32.000'

chrismetcalf
  • 1,556
  • 1
  • 8
  • 7
  • Just out of curiosity, do you know how you would write the query string to obtain the same result? – jtorca Apr 11 '17 at 18:58
  • 1
    Sorry, just noticed this one! You could write the `$query` as: `SELECT * WHERE traffic > -1 AND last_update BETWEEN '2013-01-19T23:50:32.000' AND '2014-12-14T23:50:32.000'` – chrismetcalf Jul 17 '17 at 18:48