how remove sub path from csv file [closed]

in ‘id_path’ in CSV file i want remove subpath from it such as

dataframe of csv file

i want remove all path before the image file name

./input/skin-cancer-malignant-vs-benign/data/test/benign/454.jpg

./input/skin-cancer-malignant-vs-benign/data/test/benign/90.jpg

./input/skin-cancer-malignant-vs-benign/data/test/benign/147.jpg

./input/skin-cancer-malignant-vs-benign/data/test/malignant/771.jpg

./input/skin-cancer-malignant-vs-benign/data/test/malignant/208.jpg

./input/skin-cancer-malignant-vs-benign/data/test/malignant/1383.jpg

./input/skin-cancer-malignant-vs-benign/data/test/malignant/1354.jpg

the output should be

454.jpg

90.jpg

147.jpg

771.jpg

208.jpg

1383.jpg

1354.jpg

Answer

rsplit() splits the data from the right side of the string and 1 is way of saying python to stop after first split.

txt = "./input/skin-cancer-malignant-vs-benign/data/test/benign/454.jpg"
x = txt.rsplit("/",1)
#your answer
print(x[1])

on your dataframe you could do something like:

train_df['id_path'] = train_df['id_path'].apply(lambda x: x.rsplit('/',1)[1])