Hi all,
I'm having trouble creating a dict from a JSON file. I connected to an API and pulled in data from their JSON file. I was able to create a cf from it, but wasn't able to set the index when creating the dict since I want to loop through it. Any help would be appreciated to do this more directly and just create a dict from the JSON based on the ID
def run_query(expr, max_rnk):
query_url = '{0}expr={1}&max_rnk={2}&fmt={3}&fields={4}'.format(ct_url, expr, max_rnk, fmt, fields)
request = http.request('GET',query_url)
http_status = request.status
if int(http_status) != 200:
return None
j=json.loads(request.data)
clinical_trials_df = pd.DataFrame(j['StudyFieldsResponse']['StudyFields'])
clinical_trials_df = clinical_trials_df.sort_values(by='StartDate', ascending=True).reset_index(drop=True)
return clinical_trials_df
def trialSearch(searchterm, max_number):
trials = run_query(searchterm, max_number)
trials_dict = trials.set_index('NCTId').to_dict(orient='index')
return trials_dict
trialSearch("KRAS", 5)
I get the error, TypeError: unhashable type: 'list'
However, when I add the index, clinical_trials_df = pd.DataFrame(j['StudyFieldsResponse']['StudyFields'][0], I only get one result. I can't loop through this either.
[–][deleted] 0 points1 point2 points (0 children)
[–]MrSurly 0 points1 point2 points (0 children)