Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pandas loader to dataframe list index out of range #177

Open
jhzsquared opened this issue Oct 13, 2020 · 1 comment
Open

pandas loader to dataframe list index out of range #177

jhzsquared opened this issue Oct 13, 2020 · 1 comment

Comments

@jhzsquared
Copy link

jhzsquared commented Oct 13, 2020

When trying to use pandas_loader.to_dataframe with an incompletely filled sheet, I get a IndexError: list index out of range . This is because a Cell perhaps with values of row start and end being 1, and column of 1 will only have one value in the value list, but when calling that value the extract_cell_data goes to value[1]. This only happens (I think) because when defining the sheet, I defined my first row as a list and then defined the other cells via the column.

I modified my code with the following replacement to extract_cell_data to partially fix this.

def extract_cell_data_new(cell, data):
    value = cell.value
    if cell.row_start == cell.row_end:
        col = cell.column_start
        row = cell.row_start
        for v in value:
            data[row][col]['value'] = v
            data[row][col]['options']['type'] = cell.type
            col = col+1
    else:
        row = cell.row_start
        col = cell.column_start
        for v in value:
            data[row][col]['value'] = v
            data[row][col]['options']['type'] = cell.type
            row = row+1
    
@pdavidsonFIA
Copy link

Exactly the same problem. Just using an intuitive way to create a sheet, populate first row with headers then fill with data.
Toggle the commented line to replicate the error.

from ipysheet import sheet, cell, row, column
from ipysheet import to_dataframe
sheet1 = sheet(rows=6, columns=4)
row = row(0, list(map(chr, range(ord('a'), ord('d')+1))))
column = column(0, [*range(5)] ,row_start=1)
#column = column(0,['a'] + [*range(5)] ,row_start=0)

sheet1

df = to_dataframe(sheet1)
df

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants