创建 .xlsx 文件单列的元素列表
Creating a list of elements of .xlsx file single column
我遇到了一个问题:我正在尝试在我的 .xlsx 文件的单个列中创建一个浮动列表。我有这个 IndexError: tuple index out of range
x = []
wb=load_workbook('sample_data1(dynamics).xlsx')
ws = wb.active
columnX = ws['L']
for i in range(len(columnX)):
if columnX[i+1].value != '-': %Just because in some cells of this column I have '-'
x.append(float(columnX[i+1].value))
当我尝试另一个版本的代码时:
x = []
wb=load_workbook('sample_data1(dynamics).xlsx')
ws = wb.active
columnX = ws['L']
for i in range(len(columnX)):
if columnX[i].value != '-' or columnX[i].value != 'Point of Regard Right X [px]': %Just because first cell contain 'Point of Regard Right X [px]'
x.append(float(columnX[i].value))
我有这个错误:ValueError: could not convert string to float: 'Point of Regard Right X [px]
。
那么,有人可以帮助我吗?
pandas(使用 xlrd)通常对我有用:
import pandas
df = pandas.read_excel('sample_data1(dynamics).xlsx')
col = 'REQUIRED COL'
col_values_list = list(df[col])
pandas 将处理值到浮点数的转换。
我遇到了一个问题:我正在尝试在我的 .xlsx 文件的单个列中创建一个浮动列表。我有这个 IndexError: tuple index out of range
x = []
wb=load_workbook('sample_data1(dynamics).xlsx')
ws = wb.active
columnX = ws['L']
for i in range(len(columnX)):
if columnX[i+1].value != '-': %Just because in some cells of this column I have '-'
x.append(float(columnX[i+1].value))
当我尝试另一个版本的代码时:
x = []
wb=load_workbook('sample_data1(dynamics).xlsx')
ws = wb.active
columnX = ws['L']
for i in range(len(columnX)):
if columnX[i].value != '-' or columnX[i].value != 'Point of Regard Right X [px]': %Just because first cell contain 'Point of Regard Right X [px]'
x.append(float(columnX[i].value))
我有这个错误:ValueError: could not convert string to float: 'Point of Regard Right X [px]
。
那么,有人可以帮助我吗?
pandas(使用 xlrd)通常对我有用:
import pandas
df = pandas.read_excel('sample_data1(dynamics).xlsx')
col = 'REQUIRED COL'
col_values_list = list(df[col])
pandas 将处理值到浮点数的转换。