I'm trying to filter the following pandas dataframe.
id X_1 X_2 X_4 M_1 M_2 M_3
0 i24 Nan 0.27 Nan 0.20 0.25 0.27
1 i25 0.45 0.47 0.46 0.42 Nan 0.42
2 i11 Nan Nan 0.32 0.32 0.35 0.29
3 i47 Nan 0.56 0.59 Nan 0.56 0.51
In particular, I want to treat the M_ columns and X_columns separately and keep only those entries that, for each "group" M and X, have at least two non-Nan values. E.g. entry i24 should not be included, because its values in X_1 and X_4 are both Nan, leaving only one correct value in the X "group". i25 and i47 instead should be kept, since they respect the constraints.
Thank you to anyone that can help.