The structure of my folder and file looks like this
images = glob("/content/drive/MyDrive/Colab/input/final_data/)
Inside the final_data I have a couple of files say crash_039.jpg etc. Here I am splitting the part before underscore as my class and the whole part as my image.
I expect my output to have the class names without those square brackets. The code below gives me square brackets and I am not sure what is the issue or is this normal in collab?
images = glob("/content/drive/MyDrive/Colab/input/final_data/*.jpg")
train_image = []
train_class = []
for i in tqdm(range(len(images))):
# creating the image name
train_image.append(images[i].split('/')[7])
# creating the class of image
train_class.append(images[i].split('/')[7].split('_')[:1])
# storing the images and their class in a dataframe
train_data = pd.DataFrame()
train_data['image'] = train_image
train_data['class'] = train_class
# converting the dataframe into csv file
train_data.to_csv('/content/drive/MyDrive/Colab/input/train_output/train_new.csv',header=True, index=False)
output
image class
0 crash_039.jpg [crash]
1 crash_040.jpg [crash]
expected output
image class
0 crash_039.jpg crash
1 crash_040.jpg crash
The attached image shows how the csv is storing it but I do not want those quotations and brackets around the class column.
question from:
https://stackoverflow.com/questions/66062882/split-index-on-filename-gives-me-wrong-output-in-python 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…