1

My issue right now is pretty simple i have the following dataset Dataset

And i want the path column to be aligned to it is specific pokemon, so basically if the path ends up in an pikachu image i want the Name row and the path row to also be the pikachu image path.

Here is my code and what i tried so far

for i in pok['Paths']:
split_path=i.split('/')
#print(split_path[5]
    if split_path[5] == pok['Name'][0]:
        pok['new_path'] == i 

Unfurtunately i couldnt even make the first path equal..., that was my desperate attempt. Would appreciate any help

INGl0R1AM0R1
  • 1,532
  • 5
  • 16

2 Answers2

1

The following code will extract image name without extension from Paths column and save it in Name column.

import os


pok['Name'] = pok['Paths'].apply(
    lambda x: os.path.basename(x).split('.')[0]
)

os.path.basename extracts "venomoth.png" from "../input/images/images/venomoth.png"

.split('.')[0] extracts "venomoth" from "venomoth.png"

nick
  • 463
  • 3
  • 11
  • Apreciate your answer, but to extract the name from the path itself is not exact wat i want. i just want the path that goes to the the pikachu img to be aligned with the Name row Pikachu – INGl0R1AM0R1 Nov 30 '21 at 18:47
1

 In this case you should try to do a fuzzy string search.

>>> from fuzzywuzzy import fuzz
>>> from fuzzywuzzy import process
>>>
>>> name = df['Name'].tolist()
>>> paths = df['Paths'].tolist()
>>>
>>> mat=[]
>>> for i in name:
...    mat.append(process.extract(i, paths, limit=2)) #mat1
>>> df['new_path'] = mat #mat1

user11717481
  • 1
  • 9
  • 15
  • 25
  • Yours worked perfectly love u, just a lil typo on mat variable but it is fine thank you for introducing me to that library – INGl0R1AM0R1 Nov 30 '21 at 19:08