Reputation: 55
I have this code:
val_list = []
val_list_y = []
val_list_df = pd.DataFrame([])
for img in os.listdir(exa_test_dir):
val_list.append(exa_test_dir +img)
img_name = img.split('.')[0]
val_list_y.append(val_df[val_df['filename_seconds']==img_name]['birds'].values)
val_list_df['image'] = val_list
val_list_df['label'] = val_list_y
I want to create a Dataframe which has 2 columns ['image','label']
'image'- directory for image (I get that using for loop)
'label'- name of the label
'image' is working fine for me but when extracting label I get it in the format ['....'] . I want to get the labels in the format .... not ['....']
How can I remove the [ and ' characters?
Upvotes: 0
Views: 70
Reputation: 2126
Try joining the values before each append to remove the square (list) brackets:
val_list_y.append(' '.join(val_df[val_df['filename_seconds']==img_name]['birds'].astype(str).values))
Upvotes: 1