熊猫下降的布尔值列表,它做了什么? [重复]

问题描述 投票:2回答:1

这个问题在这里已有答案:

你能解释一下这是做什么的吗?

>>> 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

谢谢

python pandas
1个回答
1
投票

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=0axis=1列的索引。

由于boolint的子类,True在旧版本的pandas中被视为1而False被视为0. df.drop不是设计用于布尔数组。对于使用df.loc的布尔索引。

要按索引位置删除行,可以为df.index提供一个列表:

df.drop(df.index[[1,3]])
© www.soinside.com 2019 - 2024. All rights reserved.