I want to drop columns if the values inside of them are the same as other columns. From DF, it should yields DF_new:
DF = pd.DataFrame(index=[1,2,3,4], columns = ['col1', 'col2','col3','col4','col5'])
x = np.random.uniform(size=4)
DF['col1'] = x
DF['col2'] = x+2
DF['col3'] = x
DF ['col4'] = x+2
DF['col5'] = [5,6,7,8]
display(DF)
DF_new = DF[['col1', 'col2', 'col5']]
display(DF_new)
Simple example of what I can't manage to do:
Note that the column names are not the same, so I can't use:
DF_new = DF.loc[:,~DF.columns.duplicated()].copy()
, which drop columns based on their names.