简体   繁体   中英

How do I check that array size?

I am trying to print all the time of Jobs with pandas.

import pandas as pd

file_name = 'cases/case1_1md_2mec_4jobs.xlsx'
xl = pd.ExcelFile(file_name)

df_jobs = xl.parse('Jobs')
df_mecs = xl.parse('MECs')
df_links = xl.parse('Links')
df_mds =   xl.parse('MD')


df_sol_time = pd.DataFrame(columns={'Jobs','Time'})
for job in df_jobs:
    job_size = df_jobs['JOB SIZE'][df_jobs['ID'] == job].item()
    MD_ID = df_jobs['MD ID'][df_jobs['ID'] == job].item()
    md_proc_speed = df_mds['PROCESSOR'][df_mds['MD ID'] == MD_ID].item()
    comp_time = float(job_size * 1024 * 1024 * 8) / (0.00227 * md_proc_speed)

I am getting this message:

Can only convert an array of size 1 to a python scalar

I don't know if I understand fully, but I'm fairly certain this will take away your scalar error and should give you what you were trying to get out of the dictionaries.

for index, job in df_jobs.iterrows():
    job_size = job['JOB SIZE']
    MD_ID = job['MD ID']
    md_proc_speed = job['PROCESSOR']
    comp_time = float(job_size * 1024 * 1024 * 8) / (0.00227 * md_proc_speed)

I'm not sure what exactly you are looking to print, but perhaps this will help.

for index, job in df_jobs.iterrows():
    job_size = job['JOB SIZE']
    MD_ID = job['MD ID']
    md_proc_speed = job['PROCESSOR']
    comp_time = float(job_size * 1024 * 1024 * 8) / (0.00227 * md_proc_speed)
    print(MD_ID, comp_time)

For a total time.

total_comp_time = 0
for index, job in df_jobs.iterrows():
    job_size = job['JOB SIZE']
    MD_ID = job['MD ID']
    md_proc_speed = job['PROCESSOR']
    comp_time = float(job_size * 1024 * 1024 * 8) / (0.00227 * md_proc_speed)
    print(MD_ID, comp_time)
    total_comp_time += comp_time
print(total_comp_time)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM