【发布时间】:2019-07-10 06:51:27
【问题描述】:
我知道这是一个简单的问题,但我就是找不到解决方法。
我有一个 DataFrame,我想根据另一个 series 中的值删除行。
X
1 2 5 6 7 10 12 13
0 5 4 4 4 0 4 0 3
1 3 0 3 0 0 0 0 3
2 4 0 0 0 0 0 0 0
3 3 0 0 0 5 4 5 5
4 3 0 0 0 0 0 0 1
Vtk
1 4
2 3
4 3
Name: rank, dtype: int64
我想从 X 中删除与 Vtk 中值 a = 3 的索引相对应的行。在这种情况下,我希望根据值 a = 3 删除 X 中索引为 2 和 4 的行。像这样:
X
1 2 5 6 7 10 12 13
0 5 4 4 4 0 4 0 3
1 3 0 3 0 0 0 0 3
3 3 0 0 0 5 4 5 5
到目前为止我已经尝试过:
b = Vtk.isin([~a])
newX = X.loc[b]
但是有 IndexingError :
IndexingError: Unalignable boolean Series provided as indexer (index of the boolean Series and of the indexed object do not match
还有其他方法可以解决我的问题吗?
【问题讨论】:
标签: python python-3.x pandas dataframe jupyter-notebook