I need to loop my df.columns so that i can dynamically apply condition to my every column through loop, i am not able to loop my column names in condition.
df:
B1 B2 B3 B4 B5
9 0 5 6 7
8 7 6 4 8
0 9 8 6 6
1 0 7 6 3
condition = [(df['B1'] == 0)| (df['B1'].isnull==False),
(df['B1'] == 8)| (df['B1'].isnull==True),
(df['B1'] == 6)| (df['B1'].isnull==False)]
values = [999,444,555]
I used to do this:
df['B1'] = np.select(condition , values) # Seperately for every column.
I am trying:
for i in df.columns:
df[i] = np.select(condition, values) # how can i able to loop i in condition, since condition is constant
Output for B1:
B1 B2 B3 B4 B5
999 0 5 6 7
999 7 6 4 8
999 9 8 6 6
999 0 7 6 3