BigQuery Python - Downstream analysis - Active Ingredient - Bar plot
# Import packages
import os, sys
from google.cloud import bigquery
from matplotlib import pyplot as plt
# Connect to client
client = bigquery.Client()
# Run the query
query = """ SELECT FVNR.Substance AS ActiveIngredient,
COUNT(*) AS N_PURCHASES
FROM `finngen-production-library.sandbox_tools_r10.finngen_r10_service_sector_detailed_longitudinal_v1` AS FDL
JOIN `finngen-production-library.medical_codes.finngen_vnr_v1` as FVNR
ON FDL.CODE3 = FVNR.VNR
WHERE FDL.SOURCE='PURCH' AND
EXTRACT(YEAR from FDL.APPROX_EVENT_DAY) = 1995 AND
FVNR.Substance IS NOT NULL AND
FDL.CODE3 IS NOT NULL
GROUP BY ActiveIngredient
ORDER BY N_PURCHASES DESC
LIMIT 10
"""
# Job configuration
job_config = bigquery.QueryJobConfig()
# Run the query
query_result = client.query(query,job_config=job_config)Last updated
Was this helpful?