Suppose I have a following dataframe:
x = pd.DataFrame(
{
'A': np.random.normal(0, 1, 100),
'B': np.random.normal(0, 1, 100),
'C': np.random.normal(0, 1, 100),
'D': np.random.normal(0, 1, 100),
'E': np.random.normal(0, 1, 100)
}
)
I want to use loc
and select only those rows where a value of certain is less than 0.5.
I know I can do this as follows:
df.loc[df.A < 0.5, :]
and for multiple columns, I can do as follows:
df.loc[(df.A < 0.5) | (df.B < 0.5) | (df.C < 0.5), :]
My question is: Is there a better way to write conditions inside loc
when you have more than 10 columns. I suppose I can do it the way I have shown above, but it becomes very tedious and I was hoping for a better way to do so.