[Python] Weird IndexError when creating hdf5 file with pandas in table mode

Discussão em 'Python' iniciado por Stack, Maio 26, 2025.

  1. Stack

    Stack Membro Participativo

    I have a very weird error when creating a hdf5 file with pandas in table mode. I create the file with the store.put() function:

    storage_file.put(some_name, current_dataset.meta_data, format="table", data_columns=True,min_itemsize={"values": 100})


    The meta_data is - obviously - a pandas dataframe with the column names:

    [
    'index',
    'xPosition',
    'yPosition',
    'approachID',
    'segment_0_type',
    'segment_0_style',
    'segment_0_duration',
    'segment_0_num_points',
    'segment_0_z_start',
    'segment_0_z_end',
    'segment_0_setpoint',
    'segment_1_type',
    'segment_1_style',
    'segment_1_duration',
    'segment_1_num_points',
    'segment_1_z_start',
    'segment_1_z_end',
    'segment_1_setpoint',
    'segment_2_type',
    'segment_2_style',
    'segment_2_duration',
    'segment_2_num_points',
    'segment_2_height_limit',
    'pauseBeforeFirst',
    'pauseOnTipsaver',
    'segmentIndex',
    'heightMultiplier',
    'heightOffset',
    'sensitivity',
    'springConstant',
    'measurementID'
    ]


    I get the following error message:

    IndexError: tuple index out of range


    together with

    File "PATH\Lib\site-packages\pandas\io\pytables.py", line 4473, in write_data
    new_shape = (nrows,) + self.dtype[names[nindexes + i]].shape


    I am sure, that there is something off with the column names, cause when I change the column names to ["0" ... "30"] with "..." the respective numbers in between, the error vanishes. The length of the column names shouldn't be a problem either cause I renamed every coumn names with

    for index in range(meta_data.shape[1]):
    meta_data.rename({meta_data.columns[index]: "".join([str(index) for i in range(25)])}, axis=1, inplace=True)


    which is incredibly ugly, but works.

    Any thoughts about this?

    Continue reading...

Compartilhe esta Página