I am trying to create two smaller dataframes based on a single one ("main Dataframe"). The first dataframe (1) should consist of all the columns of the main DataFrame for which the number of modalities is less than, say 2. The other dataframe should have all the remaining columns.
I tried several things that didn't work. Last one, I tried to return uniques in the DataFrame, sort the values and then only select those I could see matched the criteria of two modalities, in total 11 columns
Try 1:
new_df = df.iloc[df.columns[df.nunique[0] <=2]]
[TypeError: 'method' object is not subscriptable
Try 2:
new_df = df.loc[df.nunique.sort_values()[:11])]
But it returned all the columns without screening.
Could anyone help me solve this?