dataframe使用drop时已指定index报错:['搜索词', '标题', '价格', '图片地址'] not found in axis

使用drop时已指定index,但是却出现not found in axis的报错,列表内均为df.columns
df.drop(index=df[(num_price+2):(start_stop[i][1] + 1)], inplace=True, axis=0)
系统报错显示为
"['搜索词', '标题', '价格', '图片地址'] not found in axis"
尝试过修改axis无果,报错仍为上述所示
等价于删除drop.iloc[num1:num2, :]的值,按行删除

df[(num_price+2):(start_stop[i][1] + 1)]是取出的数据框,需要加上.index获取行索引,参考例子:

import pandas as pd
import random
pd.set_option('display.max_rows',None)
dt=pd.date_range('2010-01-01','2010-01-08',freq='H',inclusive='left')
df=pd.DataFrame({'date':dt,'value':[random.choice(range(100)) for _ in range(len(dt))]})
df.drop(index=df[(df['value']>50)&(df['value']<80)].index, inplace=True, axis=0)
print(df)

如有帮助,请点采纳。

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632

这个语句是删除第0行和第一行,对比一下你自己的
data.drop([0,1],axis=0,inplace=True)