XML to CSV conversion

Hello I was following the article and had a problem converting xml to csv.

I used the code that Pulkit Sir has provided

import os, sys, random
import xml.etree.ElementTree as ET
from glob import glob
import pandas as pd
from shutil import copyfile

annotations = glob('D:\\NeelaCSE\\Thesis\\BCCD_Dataset-master\\BCCD\\Annotations\\*.xml')

df = []
cnt = 0
for file in annotations:
    prev_filename = file.split('/')[-1].split('.')[0] + '.jpg'
filename = str(cnt) + '.jpg'
row = []
parsedXML = ET.parse(file)
for node in parsedXML.getroot().iter('object'):
    blood_cells = node.find('name').text
xmin = int(node.find('bndbox/xmin').text)
xmax = int(node.find('bndbox/xmax').text)
ymin = int(node.find('bndbox/ymin').text)
ymax = int(node.find('bndbox/ymax').text)

row = [prev_filename, filename, blood_cells, xmin, xmax,
ymin, ymax]
cnt += 1

data = pd.DataFrame(df, columns=['prev_filename', 'filename', 'cell_type',
'xmin', 'xmax', 'ymin', 'ymax'])

data[['filename', 'cell_type', 'xmin', 'xmax', 'ymin', 'ymax']].to_csv

i have no error in here but i dont think my csv file has generated. where will i find my converted csv file. I am new to this , help will be appreciated

You should add path here when you want to have a csv file. For example

data[[‘filename’, ‘cell_type’, ‘xmin’, ‘xmax’, ‘ymin’, ‘ymax’]].to_csv(‘C:\Users\object_detection\annotation.csv’,index=None)

Thank you . This worked but it only created one row of data i mean only for 0.jpg. What to do?

I think i have not indented it correctly

© Copyright 2013-2019 Analytics Vidhya