Deleting Rows Based On Multiple Conditions Python Pandas
I want to delete rows when a few conditions are met: For instance, a random DataFrame is generated: import pandas as pd import numpy as np df = pd.DataFrame(np.random.randn(10, 4),
Solution 1:
For reasons that aren't 100% clear to me, pandas
plays nice with the bitwise logical operators |
and &
, but not the boolean ones or
and and
.
Try this instead:
df = df[(df.one > 0) | (df.two > 0) | (df.three > 0) & (df.four < 1)]
Post a Comment for "Deleting Rows Based On Multiple Conditions Python Pandas"