我有花車的列表,它看起來像這樣:重新編碼漂浮在列表
predictions_dec = [13.0, 8.6, 4.9, -1.5, 6.2, 7.7, 2.0, 10.0, 7.7, 12.7,...]
我要清理這些數據,通過爲超過10.0 10.0較高的數量和大於0.0較低的數字(因此所有負數)a 0.0。我用下面的if語句這樣:
predictions_clean = []
for pred in predictions_dec:
if pred >= 10:
predictions_clean.append(10.0)
if pred <= 0:
predictions_clean.append(0.0)
else:
predictions_clean.append(pred)
此代碼似乎工作,但有趣的是,:
len(predictions_dec)
1222
len(predictions_clean)
1816
我的if語句不是非常瞭解。在if語句中,我做錯了什麼?
是'ratings_dec'的一個例子的' predictions_dec'? – doctorlove
是的,忘了改變它.. – Lisadk