提高python迭代器的速度

时间:2017-12-10 01:17:24

标签: python iterator gcloud

我已经在python中实现了一个大的查询作业应用程序,并部署在app引擎中,需要一些帮助来提高下面过滤器的效率,过滤器只是过滤为输入的用户电子邮件

credentials = GoogleCredentials.get_application_default()
bq_conn= discovery.build('bigquery', 'v2', credentials=credentials)

job_query_dict = []    


###Create the big query client
client =bigquery.Client(project=project_id)


###List the jobs in the client
jobs = client.list_jobs(all_users=True)   # API request
print( [job for job in list(client.list_jobs(all_users=True)) if job.user_email==user_email][0])

如何打印user_email输入中给出的用户的作业比这更好?

1 个答案:

答案 0 :(得分:0)

作为pandas数据帧访问作业数据比从列表中访问

更快
t=bigquery_service.jobs().list(projectId=project_id,allUsers=True,projection='full',stateFilter=job_state.lower()).execute()
try:
    tab = pd.DataFrame(t['jobs'])    
except:
    return "No jobs"