0

I am trying to dynamically create column names for a df using some code by using lists.

What I don't understand is why my code isn't detecting bnhSTD figures I may be just missing something obvious. In trying to find the error I have added the print statements print tag == to the example 33bnhStd which you can see does exist in the final output of tags. I have added remove tag to speed up subsequent iterations.

It should print out 33bnhSTD 3 times sequentially but it only prints it out the first two and I have no clue why this is. I am wondering if someone can explain why it is not finding it all of a sudden. It does find correctly the tags with indSTD in them and appends them to my main list and removes the indSTD tags from tags. But for some reason it cant find the bnhSTD ones to then delete them so when I call tags again there they are and it can find the specific tag within those tags.

for tag in tags:    
    if "Corr" in tag:       
        if "bnh" in tag:
            tags.remove(tag)
        else:           
            colTagList.append(tag)
            tags.remove(tag)
    else:
        if tag == "33bnhSTD":
            print(tag)
        pass
for tag in tags:
    if tag == "33bnhSTD":
        print(tag)      
for tag in tags:
    if tag == "33bnhSTD":
        print(tag)
    if "Max" in tag:
        if "ind" in tag:
            colTagList.append(tag)
            tags.remove(tag)
        else:
            tags.remove(tag)
    else:
        pass
for tag in tags:

    if "STD" in tag:        
        if "ind" in tag:
            colTagList.append(tag)
            tags.remove(tag)
        else:
            tags.remove(tag)
print(tags)

for tag in tags:
    if tag == "33bnhSTD":
            print(tag)

Output:

33bnhSTD
33bnhSTD
['03bnhSTD', '05bnhSTD', '010bnhSTD', '015bnhSTD', '020bnhSTD', '030bnhSTD', '040bnhSTD', '060bnhSTD', '080bnhSTD', '0100bnhSTD', '0120bnhSTD', '0150bnhSTD', '0250bnhSTD', '13bnhSTD', '15bnhSTD', '110bnhSTD', '115bnhSTD', '120bnhSTD', '130bnhSTD', '140bnhSTD', '160bnhSTD', '180bnhSTD', '1100bnhSTD', '1120bnhSTD', '1150bnhSTD', '1250bnhSTD', '23bnhSTD', '25bnhSTD', '210bnhSTD', '215bnhSTD', '220bnhSTD', '230bnhSTD', '240bnhSTD', '260bnhSTD', '280bnhSTD', '2100bnhSTD', '2120bnhSTD', '2150bnhSTD', '2250bnhSTD', '33bnhSTD', '35bnhSTD', '310bnhSTD', '315bnhSTD', '320bnhSTD', '330bnhSTD', '340bnhSTD', '360bnhSTD', '380bnhSTD', '3100bnhSTD', '3120bnhSTD', '3150bnhSTD', '3250bnhSTD']
33bnhSTD
[Finished in 1.9s]
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
JPWilson
  • 691
  • 4
  • 14

0 Answers0