Improve login in `parse_data`.
This commit is contained in:
parent
e96fb14710
commit
37c52355f4
|
|
@ -12,7 +12,9 @@ def parse_data(backend, rows, headers=True, columns=None, skiprows=0):
|
||||||
next(rows)
|
next(rows)
|
||||||
for i, row in enumerate(rows):
|
for i, row in enumerate(rows):
|
||||||
# row is a list of cells
|
# row is a list of cells
|
||||||
if headers and i == 0 and not columns:
|
if i == 0:
|
||||||
|
if not columns:
|
||||||
|
if headers:
|
||||||
repeat_until = -1
|
repeat_until = -1
|
||||||
repeat_value = None
|
repeat_value = None
|
||||||
# columns as lists in a dictionary
|
# columns as lists in a dictionary
|
||||||
|
|
@ -37,15 +39,17 @@ def parse_data(backend, rows, headers=True, columns=None, skiprows=0):
|
||||||
while f"{column_name}.{idx}" in columns:
|
while f"{column_name}.{idx}" in columns:
|
||||||
idx += 1
|
idx += 1
|
||||||
columns.append(f"{column_name}.{idx}")
|
columns.append(f"{column_name}.{idx}")
|
||||||
elif i == 0:
|
else:
|
||||||
# without headers, assign generic numbered column names
|
# without headers, assign generic numbered column names
|
||||||
columns = columns if columns else [f"column.{j}" for j in range(len(row))]
|
columns = [f"column.{j}" for j in range(len(row))]
|
||||||
if i == 0:
|
|
||||||
df_dict = OrderedDict((column, []) for column in columns)
|
df_dict = OrderedDict((column, []) for column in columns)
|
||||||
# create index for the column headers
|
# create index for the column headers
|
||||||
col_index = {j: column for j, column in enumerate(columns)}
|
col_index = {j: column for j, column in enumerate(columns)}
|
||||||
|
|
||||||
if headers:
|
if headers:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for j, cell in enumerate(row):
|
for j, cell in enumerate(row):
|
||||||
if j < len(col_index):
|
if j < len(col_index):
|
||||||
value, _ = backend.get_value(cell, parsed=True)
|
value, _ = backend.get_value(cell, parsed=True)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue