0
votes

I have a column in the dataframe that contains a sting that ends with a location code. for example: Growers SeGrowersSecret 14AG CHEM

locations = ["AG CHEM", "AG SEED", "BH CHEM", "BH FARM", 'BH GREEN', 'CT CHEM', 'Bighorn Farm', 'Courthouse Farm']

df["Location Code"] = ""

loc = []

for i in df["str"]:
    stlen = len(i)
    
    for x in locations:
        loclen = len(x)
        start, stop = stlen - loclen, 50
        if :
            loc.append(x)

df["Location Code"]  = loc   

the locations list contains all the possible locations. i want to compare the list to that portion of the string, and have a separate column in the dataframe for locations. I tried str.endswith() but it didn't work neither.

All help is very appreciated!