ValueError: could not convert string to float: '' in python numpy

I am new to numpy and have a problem. after running these lines of code I get an error! ValueError: could not convert string to float: ''

wb = r"C:\\Users................\df.xls"
def create_array(wb):
    sheet = xlrd.open_workbook(wb).sheet_by_index(0)
    wb_list = [sheet.row_values(i) for i in range(sheet.nrows)]
    return np.array (wb_list)
arr = create_array(wb)
df = arr[1:, 1:]
df
pid =0
age = 1
BMI = 2
PA_Score_Cat = 3
WS_Q = 4
Residence =5
adata = df[:, age].astype(float)
def stat_calcs(adata, df):
    print ('Average of all ages is \t', adata.mean().round(2))
    print ('Median of all ages is \t', np.median(adata).round(2))
    print ('Maximum of all ages is \t', adata.max().round(2))
    print ('Minimum of all ages is \t', np.min(adata).round(2))
    print ('SD of all ages is \t', adata.std().round(2))
    print ()
    
    ind_max = adata.argmax()
    print ("Maximum age is %d with %s pid, whose BMI is %s"\
           "and lives in %s"%(adata[ind_max], df[ind_min, pid], df[ind_max, BMI], df[ind_max, Residence]))
    ind_min = adata.argmin()
    print ("Maximum age is %d with %s pid, whose BMI is %s"\
           "and lives in %s"%(adata[ind_min], df[ind_min, pid], df[ind_min, BMI], df[ind_max, Residence]))
           
print("*** All Calculations ***")
stat_calcs(adata, df)


ValueError Traceback (most recent call last)
in
13 WS_Q = 4
14 Residence =5
---> 15 adata = df[:, age].astype(float)
16 def stat_calcs(adata, df):
17 print ('Average of all ages is \t', adata.mean().round(2))

ValueError: could not convert string to float: ''

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.