I have a method that is not very good.
df1 = pd.DataFrame([[['and', 'or'],['1', '2','3','4','5'],['@', '$','&']]],columns=['Alpha','Numeric','Special'])
print(df1)
Alpha Numeric Special
0 [and, or] [1, 2, 3, 4, 5] [@, $, &]
df2 = pd.DataFrame([[['boy', 'or','girl']],[['school', '@','morn']]],columns=['Content'])
print(df2)
Content
0 [boy, or, girl]
1 [school, @, morn]
First, combine the df2 data:
df2list=[x for row in df2['Content'].tolist() for x in row]
print(df2list)
['boy', 'or', 'girl', 'school', '@', 'morn']
Then get data of each column of df1 is intersected with the df2list:
containlistname = []
for i in range(0,df1.shape[1]):
columnsname = df1.columns[i]
df1list=[x for row in df1[columnsname].tolist() for x in row]
intersection = list(set(df1list).intersection(set(df2list)))
if len(intersection)>0:
containlistname.append(columnsname)
output_DF = pd.DataFrame(containlistname,columns=['output_column'])
Final print:
print(output_DF)
output_column
0 Alpha
1 Special