Which columns are binary in a Pandas DataFrame?
You can just use the unique() function from pandas on each column in your dataset.
ex: df["colname"].unique()
This will return a list of all unique values in the specified column.
You can also use for loop to traverse through all the columns in the dataset.
ex: [df[cols].unique() for cols in df]
I have a pandas dataframe with a large number of columns and I need to find which columns are binary (with values 0 or 1 only) without looking at the data. Which function should be used?