I have a main DF and then a sub-DF that I want to insert within the main DF, between two rows. So the index of the first DF is ..., 183, 184, 185, 186, 187... I want to insert a five-row DF in between rows 185 and 186 in the main DF.
To do this, I am trying to set the index of the sub-DF to numbers between 185 and 186, and then reindex, but I am getting a key error on the first row.
The index list is [185.01, 185.02, 185.03, 185.04, 185.05]. The error is "KeyError: 185.01"
I feel like this should be possible based on this thread: Is it possible to insert a row at an arbitrary position in a dataframe using pandas?
# reset then set index for inserting these rows after the rest of the items for this subtest
row_index.clear()
row_index = [round((last_subtest_item_index + 0.01) + (x * 0.01),2) for x in range(0, var_counter)]
print(last_subtest_item_index, row_index)
print(new_custom_table)
# TRY TO INSERT THE CUSTOM TABLE DF INTO THE MAIN DF AND SEE IF IT GOES IN-LINE WITH THE REST OF THAT CRF
new_custom_table.set_index(keys = row_index, inplace = True)
self.full_CRF = self.full_CRF.append(new_custom_table, ignore_index = False).sort_index().reset_index(drop=True)