简体   繁体   中英

Collect dataframes from List of Dataframes

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])

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])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM