0
我有一個數據框,我嘗試從該值中刪除項目。基於條件語句從.loc中刪除項目
for i in range (1, len(df['column1'])):
if df['column1'].iloc[i][0] < 2.5:
del df['column1'].iloc[i]
收到的錯誤:
AttributeError Traceback (most recent call last)
<ipython-input-80-8b343357b723> in <module>()
16 for i in range (1, len(df_agg2['water_amount']-1)):
17 if df_agg2['water_amount'].iloc[i][0] < 2.5:
---> 18 del df_agg2['water_amount'].iloc[i]
AttributeError: __delitem__
例如:
df['column1'].iloc[1]
回報:
sum 1.422883
Name: 4, dtype: float64
和,
df['column1'].iloc[1][0]
個
回報:
1.4228829999999981
我怎樣才能避免這種情況我上面得到,爲了如果是小於2.5刪除項目的AttributeError的?
是否要刪除'column1' <2.5的整行? – languitar
您可以發佈數據框df的示例數據嗎? –
@languitar是的,那是我的目標。 – Gary