results#

relationalai.Context
Context.results

Returns the results of a query. By default, results are returned as a pandas DataFrame. If the query is called with format="snowpark", the results are returned as a Snowpark ResultBatch object.

Returns#

A pandas DataFrame or a Snowpark ResultBatch object.

Example#

Access .results after selecting results in a query:

import relationalai as rai

model = rai.Model("people")
Person = model.Type("Person")

with model.rule():
    Person.add(name="Alice", age="31")
    Person.add(name="Alice", age="27")
    Person.add(name="Bob", author="19")

with model.query() as select:
    person = Person()
    response = select(person.name, person.age)

print(response.results)
# Output:
#     name age
# 0  Alice  27
# 1  Alice  31
# 2    Bob  19

Calling a ContextSelect object, like select in the preceding query, returns its Context object. In this case, response is the Context object created by model.query() in the with statement.

By default, results are in ascending lexicographic order. In the preceding example, all names beginning with A come first, followed by names starting with B, and so on. If two names are the same, such as the two people named "Alice", the remaining columns are used to determine the sort position of the rows. In this case, the row for the 27-year-old Alice comes first.

Refer to the pandas docs for details on working with pandas DataFrames.

See Also#