My df contains many columns. I want to replace all values only in columns A and B with NaN according to a condition. Also, I want to apply the same condition to another df except on columns C and D. My search so far returns methods that work for a single column.
My attempt so far.
Only on columns A and B:
df[df.loc[:, df.columns['A','B']] < (0.1 * 500)] = np.nan
Except columns A and B:
df[df.loc[:, df.columns != ['A','B']] < (0.1 * 500)] = np.nan
These code doesn't work.