1

I am trying to loop through a DF column and get just the URL key from a column of strings. I have printed every stage of this loop and it works correctly. However when printing the DF after the loop I only see the column I create with the correct values and the loop has now replaced other values in those rows a NaN. what am i doing wrong here? #clean playlists link for just key and create new column 'key'

for i, value in enumerate(tats['Playlist Link'].values):
    splitstring = str(value).split('/')
    value = splitstring[len(splitstring)-1]
    if "?" in value:
        value = value[0:value.index('?')]
    else:
        value = value
    tats.loc[i, 'key'] = value   
2
  • you may want to fix the indentation after the for loop Commented Mar 1, 2021 at 16:21
  • please elaborate for a noob like myself Commented Mar 1, 2021 at 16:39

1 Answer 1

0

Try:

for i, value in zip(tats.index, tats['Playlist Link'].values):
    ...
Sign up to request clarification or add additional context in comments.

2 Comments

i like your style, friend. works like a charm
Welcome my bro.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.