Sebastián
Sebastián

Reputation: 457

Filtering excel data to another excel with pandas

I am training a CNN, an excel has many classes to train and I just want to work with only 3.

What happens is that when I'm filtering it, in the header it comes out ", img_name, name" that comma at the beginning I don't know where it comes from, nor how it was done.

Attached code

# This might takes a while to search all these urls
subperson_img_url = [images_boxable[images_boxable['image_name']==name+'.jpg'] for name in subperson_img_id]
subphone_img_url = [images_boxable[images_boxable['image_name']==name+'.jpg'] for name in subphone_img_id]
subcar_img_url = [images_boxable[images_boxable['image_name']==name+'.jpg'] for name in subcar_img_id]


    subperson_pd = pd.DataFrame()
    subphone_pd = pd.DataFrame()
    subcar_pd = pd.DataFrame()
    for i in range(len(subperson_img_url)):
        subperson_pd = subperson_pd.append(subperson_img_url[i], ignore_index = True)
        subphone_pd = subphone_pd.append(subphone_img_url[i], ignore_index = True)
        subcar_pd = subcar_pd.append(subcar_img_url[i], ignore_index = True)
    subperson_pd.to_csv('/content/drive/My Drive/AI/Dataset/Open Images Dataset v4 (Bounding Boxes)/subperson_img_url.csv')
    subphone_pd.to_csv('/content/drive/My Drive/AI/Dataset/Open Images Dataset v4 (Bounding Boxes)/subphone_img_url.csv')
    subcar_pd.to_csv('/content/drive/My Drive/AI/Dataset/Open Images Dataset v4 (Bounding Boxes)/subcar_img_url.csv')

So, when it saved in that location, when I open it, it appears like the image below:

enter image description here

Does anyone know what I am wrong about? any help is fine, thanks!

Upvotes: 1

Views: 81

Answers (1)

Andrea
Andrea

Reputation: 3077

If you save the file using .to_csv the default behavior is to save the index as well, but you have not defined the index name, therefore you have the empty string and a comma.

To solve this you can either omit the index:

subcar_pd.to_csv(filename, index=False)

or name it:

subcar_pd.to_csv(filename, index=True, index_label='index')

Upvotes: 1

Related Questions