Quantcast
Channel: Data Science, Analytics and Big Data discussions - Latest topics
Viewing all articles
Browse latest Browse all 4448

Having error "name 'file' is not defined" in Xml to CSV conversion

$
0
0

I used the code that Pulkit Sir has provided in one blog-

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

annotations = glob(‘C:\Users\BCCD_Dataset-master\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]
df.append(row)
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(‘C:\Users\BCCD_Dataset-master\BCCD_Dataset-master\BCCD\csv.csv’,index=None)

It is showing error as - name ‘file’ is not defined

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 4448

Trending Articles