dimanche 23 février 2020

Applying Nested If condition to dataframe -Python

I am connecting to sql database and generating data frame with sleep time of 5 mins for 2 hour between 4 to 6 AM and trying to check job status ,below are conditions which i m trying to implement

check if any job is RUNNING and check it if its taking within estimated time If yes then print (" is running fine within estimated time ") else print(" has passed out of estimated time ")

else check if last job is completed then print("all jobs completed")

Come out of loop

Below is the data

enter image description here

i=0
while i <12:

    todays_run="select * from table where getdate()=startdate"  /*Checking for rundate as todays date*/
    result=pd.read_sql(todays_run,sql_conn)
    if result.empty:
        print(' No jobs are running  :')
    elif result[result.status=='RUNNING' and result.start_date <result.estimated_end]:
        print("Below  jobs are currently running with estimated time \n\n ",result)
    else result[result.status=='COMPLETED' and result.jobname='A']
        print("all jobs are completed \n \n ")
    time.sleep(60)
exit(1)

I m getting into error ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Can you please help ,if this is possible to implement using pthon

Aucun commentaire:

Enregistrer un commentaire