I want to find the common columns between a list of Data frames, the way that I started is, I defined x1 that is a lists of list ( for each data frames columns name), then I extract each sub list to a separate list.
I have the output as follows:
lst_1=['a1,a2,a3']
which has to be as follows, to be able to use set(lst_1) & set(lst_2)& etc :
lst_1=["a1","a2","a3"']
The code
x1=[]
dfs = [list of df]
for i, df in enumerate(dfs):
x1.append([",".join((str(i) for i in df.columns))])
globals()[f'lst_{i}']= x1[i]
>Solution :
reduce with set intersection
from functools import reduce
common = reduce(lambda a, b: set(a) & set(b), dfs)