My issue right now is pretty simple i have the following 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
CodePudding user response:
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:
... mat1.append(process.extract(i, paths, limit=2))
>>> df['new_path'] = mat1
CodePudding user response:
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"