python字符str转化为float


import xlrd as xd
data =xd.open_workbook ('豆瓣电影数据.xls') #打开excel表所在路径
sheet = data.sheet_by_name('豆瓣电影数据')  #读取数据,以excel表名来打开
d1 = []
for r in range(sheet.nrows): #将表中数据按行逐步添加到列表中,最后转换为list结构
    data1 = []
    for c in range(sheet.ncols):
        data1.append(sheet.cell_value(r,c))
    d1.append([i for i in data1 if i and i !=''])

print(d1)

想把'142'引号去掉,有什么办法吗

img

float(str)


    d1.append([float(i) for i in data1 if i and i !=''])
import xlrd as xd
data =xd.open_workbook ('豆瓣电影数据.xls') #打开excel表所在路径
sheet = data.sheet_by_name('豆瓣电影数据')  #读取数据,以excel表名来打开
d1 = []
for r in range(sheet.nrows): #将表中数据按行逐步添加到列表中,最后转换为list结构
    data1 = []
    for c in range(sheet.ncols):
        data1.append(sheet.cell_value(r,c))
    d1.append([float(i) for i in data1 if i and i !=''])

print(d1)

```