这个问题在这里已有答案:
你能解释一下这是做什么的吗?
>>> df = pd.DataFrame(np.arange(12).reshape(3,4),
columns=['A', 'B', 'C', 'D'])
>>> df.drop([True, True])
A B C D
0 0 1 2 3
2 8 9 10 11
>>> df.drop([True, True, True, True, True, True])
A B C D
0 0 1 2 3
2 8 9 10 11
谢谢
pd.DataFrame.drop
documentation在这里帮助:
DataFrame.drop(labels=None, axis=0, index=None, columns=None,
level=None, inplace=False, errors='raise')
axis=0
默认表示默认情况下drop
应用于行。labels
表示axis=0
或axis=1
列的索引。由于bool
是int
的子类,True
在旧版本的pandas
中被视为1而False
被视为0. df.drop
不是设计用于布尔数组。对于使用df.loc
的布尔索引。
要按索引位置删除行,可以为df.index
提供一个列表:
df.drop(df.index[[1,3]])