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