I have the following dataframes in python
dataframe_list= []## CREATE AN EMPTY LIST
import pandas as pd
A=pd.DataFrame()
A["name"]=["A", "A", "A"]
A["Query"]=["B", "B", "B"]
B=pd.DataFrame()
B["name"]=["A", "A", "A"]
B["Col"]=["query", "B", "B"]
C=pd.DataFrame()
C["name"]=["A", "A", "A"]
C["Col"]=["C", "B", "B"]
dataframe_list.append(A)
dataframe_list.append(B)
dataframe_list.append(C)
The list of dataframes contain 3 dataframes in this toy example. I would like to obtain a list of dataframes containing the word query either as a column name or as a table entry. IHow do I accomplish this. I tried the following loop
dataframe_list2=[]
for i in dataframe_list:
for column in i:
try:
m1=i[column].str.contains('query').sum()
column = column.lower()
m2 = column.count("query")
mel_count = m1+m2
except:
pass
dataframe_list2.append(i)
This however results in a a list with duplicate entries. I want each table to be mentioned just once. Is there a simple elegant solution for this.
set(list)