我的数据框中有一列称为“数据”。我尝试使用 For 循环将每个值替换为其出现的第一个实例的编号。例如
BatchID -> BatchID
Lot 11 1
Lot 11 1
Lot 11 1
Lot 11 1
Lot 12 2
Lot 12 2
Lot 13 3
Lot 14 4
Lot 14 4
Lot 14 4
这是我的代码:
unique_batches = ['Lot 11', 'Lot 12', 'Lot 13', 'Lot 14']
for i in range(len(data['BatchID'])):
for batch in unique_batches:
if data['BatchID'][i][:6] == batch:
data['BatchID'][i] = unique_batches.index(batch) + 1
这是我收到的错误:
TypeError: 'int' object is not subscriptable
---> 69 if data['BatchID'][i][:10] == batch:
神不在的星期二
猛跑小猪
相关分类