Zakir..
7
我将扩展@User的通用解决方案以提供drop免费的替代方案。这是针对根据问题标题(不是OP的问题)定向到此处的人员的
假设您要删除所有带有负值的行。一种班轮解决方案是:-
df = df[(df > 0).all(axis=1)]
逐步说明:-
让我们生成一个5x5随机正态分布数据帧
np.random.seed(0)
df = pd.DataFrame(np.random.randn(5,5), columns=list('ABCDE'))
A B C D E
0 1.764052 0.400157 0.978738 2.240893 1.867558
1 -0.977278 0.950088 -0.151357 -0.103219 0.410599
2 0.144044 1.454274 0.761038 0.121675 0.443863
3 0.333674 1.494079 -0.205158 0.313068 -0.854096
4 -2.552990 0.653619 0.864436 -0.742165 2.269755
设条件为删除负片。满足条件的布尔df:
df > 0
A B C D E
0 True True True True True
1 False True False False True
2 True True True True True
3 True True False True False
4 False True True False True
满足条件的所有行的布尔系列 注意,如果该行中的任何元素失败&