Используйте DataFrame.nunique
для фильтрации только по уникальным столбцам:
df = df.loc[:, df.nunique().eq(1)]
print (df)
3 4
0 fruit edible
1 fruit edible
2 fruit edible
3 fruit edible
А затем для списка one list DataFrame
по Series.to_frame
:
L = [df1[x].to_frame() for x in df1.columns]
print (L)
[ 3
0 fruit
1 fruit
2 fruit
3 fruit, 4
0 edible
1 edible
2 edible
3 edible]
print (L[0])
3
0 fruit
1 fruit
2 fruit
3 fruit
print (L[1])
4
0 edible
1 edible
2 edible
3 edible
А для динамического c используется pring join
с f-string
s:
print (f'Column {", ".join(df1.columns.astype(str))} have common values')
Column 3, 4 have common values