-
[데이터 전처리] xml 파일에서 class 변경Python 2021. 8. 26. 12:11
예제 코드
from glob import glob from xml.etree.ElementTree import parse Annotations = glob('valid/*.xml') classes = ['심','심','한','개','발','자'] for annotation in Annotations: tree = parse(annotation) xml = tree.getroot() object = xml.findall('object') for obj_idx, obj in enumerate(object): cls_name = obj.find('name').text if cls_name == 'a' or cls_name == 'b': obj.find('name').text = '심' elif cls_name == 'c': obj.find('name').text = '심' elif cls_name == 'd': obj.find('name').text = '한' elif cls_name == 'e': obj.find('name').text = '개' elif cls_name == 'f': obj.find('name').text = '발' elif cls_name == 'g': obj.find('name').text = '자' tree.write(annotation)
'Python' 카테고리의 다른 글
[pymodbus] PLC 32bit 쓰기 (0) 2023.01.10 OPC 프로토콜 (0) 2022.07.15 [데이터 전처리] txt 파일 xml 변환(txt2xml) (1) 2021.08.26