您可以通过条件切片和数据帧的索引属性来实现这一点remove_n = 10remove_class = 1# Here you first find the indexes where class is equal to the class you want to drop.#Then you slice only the first n indexes of this classindex_to_drop = data.index[data['class'] == remove_class][:remove_n]#Finally drop those indexesdata = data.drop(index_to_drop)