Querying data

Basic example

Python
R
Python
import redivis
# Perform a query on the Demo CMS Medicare data. Table at https://redivis.com/demo/datasets/1754/tables
query = redivis.query("""
SELECT * FROM demo.cms_2014_medicare_data.home_health_agencies
WHERE state = 'CA'
""")
for row in query.list_rows():
print(row['agency_name'])
# We can also use data frames
df = query.to_dataframe();
print(df)
R
# Perform a query on the Demo CMS Medicare data.
# Table at https://redivis.com/demo/datasets/1754/tables
data <- (
redivis::query("
SELECT * FROM demo.cms_2014_medicare_data.home_health_agencies
WHERE state = 'CA'
")
$to_tibble()
)
print(data) # data is a tibble

Scoping queries

If all tables are in the same dataset / project...

Python
R
Python
import redivis
# Perform a query on the Demo CMS Medicare data. Table at https://redivis.com/demo/datasets/1754/tablesd
# We don't need to include fully-qualified table names if we scope our query to the appropriate dataset or project
query = (
redivis
.organization("Demo")
.dataset("CMS 2014 Medicare Data")
.query("""
SELECT provider_name, average_total_payments
FROM nursing_facilities
INNER JOIN outpatient_charges USING (provider_id)
WHERE state = 'CA'
""")
)
for row in query.list_rows():
print(row.agency_name)
# We can also use data frames
df = query.to_dataframe();
print(df)
R
# Perform a query on the Demo CMS Medicare data.
# Table at https://redivis.com/demo/datasets/1754/tables
# We don't need to include fully-qualified table names
# if we scope our query to the appropriate dataset or project
data <- (
redivis::organization("Demo")
$dataset("CMS 2014 Medicare Data")
$query("
SELECT provider_name, average_total_payments
FROM nursing_facilities
INNER JOIN outpatient_charges USING (provider_id)
WHERE state = 'CA'
")
$to_tibble()
)
print(data)