When I used the below code and an IndexError occurred. Where the details are shown below.
def get_code(seq):
return [x.split('.')[0] for x in seq if x]
all_codes = get_code(all_cats)
code_index = pd.Index(np.unique(all_codes))
dummy_frame = df(np.zeros((len(data), len(code_index))), index=data.index, columns=code_index)
for row, cat in zip(data.index, data.CATEGORY):
codes = get_code(to_cat_list(cat))
dummy_frame.iloc[row, codes] = 1
data = data.join(dummy_frame.add_prefix('category_'))
data.iloc[:, 10:15]
Below shown is the IndexError that occurred.
---------------------------------------------------------------------------
IndexError: only integers, slices (`:`), ellipsis (`...`), numpy.newaxis (`None`) and integer or boolean arrays are valid indices
---------------------------------------------------------------------------
However, the error occurs on the below line of code,
dummy_frame.iloc[row, codes] = 1
How can I resolve the above error to get the below information.
category_1 100 non-null values
category_1a 100 non-null values
category_1b 100 non-null values
category_1c 100 non-null values
category_1d 100 non-null values