我有一个包含 25000 行的数据框,其中包含两列(文本,类)类包含许多 [A,B,C]data = pd.read_csv('E:\mydata.txt', sep="*")data.columns = ["text", "class"]我需要删除例如10行A类,15行B类
2 回答
绝地无双
TA贡献1946条经验 获得超4个赞
您可以通过条件切片和数据帧的索引属性来实现这一点
remove_n = 10
remove_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 class
index_to_drop = data.index[data['class'] == remove_class][:remove_n]
#Finally drop those indexes
data = data.drop(index_to_drop)
添加回答
举报
0/150
提交
取消