I have a list of dataframes, and I want to create a new list of dataframes but only extract the dataframes which contains variables from A to C. My problem is if a dataframe contains more than one of these variables it gets duplicated in the new list and I don't know how to stop this... Any help would be greatly appreciated. This is my code below...
Collection=[]
for i in range(len(db)):
for col in db[i]:
if col.startswith('A') or col.startswith('B') or col.startswith('C'):
Collection.append(db[i])
CodePudding user response:
try in this way:
Collection=[]
for i in range(len(db)):
if any(col.startswith(x) for x in ["a","b","c"] for col in db[i]):
Collection.append(db[i])