I have a dataframe named AH, with columns F1 and F2:
F1 F2
aq ab
ac my
(and so on)
I wanted to make another column and classify each column first so it will become:
F1 Category1 F2 Category2
aq 77 ab 11
ac 77 my 55
The data are preprocessed already and I have made this code:
for len in range (AH):
if AH ['F1'] =={'aq','ac'}:
AH.loc[index, 'Category1'] = '77'
elif AH ['F2'] =={'ab'}:
AH.loc[index, 'Category1'] = '11'
elif AH ['F2'] =={'my'}:
AH.loc[index, 'Category1'] = '55'
else:
'NaN'
However, the error showed:
TypeError: 'DataFrame' object cannot be interpreted as an integer
Anyone who can answer?
Aucun commentaire:
Enregistrer un commentaire