-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
Problem in the following block of code:
def expert_finder(topic, client):
Returns a DataFrame with the user IDs who have written Stack Overflow answers on a topic.
Inputs:
topic: A string with the topic of interest
client: A Client object that specifies the connection to the Stack Overflow dataset
Outputs:
results: A DataFrame with columns for user_id and number_of_answers. Follows similar logic to bigquery_experts_results shown above.
'''
my_query = """
SELECT a.owner_user_id AS user_id, COUNT(1) AS number_of_answers
FROM `bigquery-public-data.stackoverflow.posts_questions` AS q
INNER JOIN `bigquery-public-data.stackoverflow.posts_answers` AS a
ON q.id = a.parent_Id
WHERE q.tags like '%{topic}%'
GROUP BY a.owner_user_id
"""
# Set up the query (a real service would have good error handling for
# queries that scan too much data)
safe_config = bigquery.QueryJobConfig(maximum_bytes_billed=10**10)
my_query_job = client.query(my_query, job_config=safe_config)
# API request - run the query, and return a pandas DataFrame
results = my_query_job.to_dataframe()
return results
Problem
my_query is not passed as a formmated string hence at WHERE q.tags like '%{topic}%' , {topic} will be taken as a string literal not as the topic argument
Expected code:
. . .
my_query = f """
SELECT a.owner_user_id AS user_id, COUNT(1) AS number_of_answers
FROM bigquery-public-data.stackoverflow.posts_questions AS q
INNER JOIN bigquery-public-data.stackoverflow.posts_answers AS a
ON q.id = a.parent_Id
WHERE q.tags like '%{topic}%'
GROUP BY a.owner_user_id
"""
. . .
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels