I am trying to delete the columns where the non zeros is less than a said number.This is the code I got but it is giving the same answer.What am I doing wrong?
df = pd.DataFrame([[1,0,0,0], [0,0,1,0]])
0 1 2 3
0 1 0 0 0
1 0 0 1 0
df = df.loc[:, (df.astype(bool).sum(axis=0) <= max_number_of_zeros)]
0 1 2 3
0 1 0 0 0
1 0 0 1 0
edit-- example-
0 1 2 3
0 1 0 0 0
1 2 0 1 0
2 0 2 3 4
3 1 1 1 1
output would be for value=2 the columns 0 and column 2
0 1 2 3
0 1 0 0 0
1 2 0 1 0
2 0 2 3 4
3 1 1 1 1