Python advanced deleting text in a column

64 Views Asked by At

Hello everyone I have a database that kicks out song names with the folders and was wondering if there was a way that a python script could delete some of the text.

My data:

https://location.com/loaction/folder1/album/songname.mp3
https://location.com/loaction2/folder2/album/songname1.mp3
https://location.com/loaction3/folder3/album/songname2.mp3
https://location.com/loaction4/folder4/album/songname3.mp3
https://location.com/loaction5/folder5/album/songname4.mp3

and was wondering if there was a way to get it to look like this.

songname.mp3
songname1.mp3
songname2.mp3
songname3.mp3
songname4.mp3
1

There are 1 best solutions below

5
On

Using str.rsplit:

>>> 'https://location.com/loaction2/folder2/album/songname1.mp3'.rsplit('/', 1)
['https://location.com/loaction2/folder2/album', 'songname1.mp3']

>>> 'https://location.com/loaction2/folder2/album/songname1.mp3'.rsplit('/', 1)[-1]
'songname1.mp3'