I have my dataframe:
And I would like to create a subset of this dataframe with the columns in which there are the fewest NaN values (i.e. the most "valid" values)
In this case, I would only select the "A3" column as there is only one NaN and there are 3 in the others.
If there are two columns (or more) with the same number of NaN values, just select one of them (for example the first it does not matter).
The code for creating the dataframe:
df = pd.DataFrame({"A1":[np.NaN,1,0,0,np.NaN,0,1,np.NaN,0,0,0,1],
"A2":[0,1,np.NaN,0,1,np.NaN,1,0,np.NaN,0,0,1],
"A3":[0,1,np.NaN,0,1,0,1,0,0,0,0,2]})
df
