我正在尝试将xml文件转换为csv文件。以下是我到目前为止所尝试的内容

时间:2018-06-04 20:24:19

标签: python-2.7 tensorflow

  import os
 import glob
 import pandas as pd
 import xml.etree.ElementTree as ET

 def xml_to_csv(path):
 xml_list = []
对于glob.glob中的xml_file(path +'/ * .x'):
 tree = ET.parse(xml_file)
 root = tree.getroot()
对于root.findall('object')中的成员:
 value =(root.find('filename')。text,
 int(root.find('size')[0] .text),
 int(root.find('size')[ 1] .text),
 member [0] .text,
 int(member [4] [0] .text),
 int(member [4] [1] .text) ,
 int(member [4] [2] .text),
 int(member [4] [3] .text)
)
 xml_list.append(值)
 column_name = ['filename','width','height','class','xmin','ymin','xmax','ymax']
 xml_df = pd.DataFrame(xml_list,columns = column_name)
返回xml_df


 def main():
 image_path = os.path.join(os.getcwd(),“/ images”)
 xml_df = xml_to_csv(image_path)
 xml_df.to_csv('baby_labels.csv',index = None)
在成功运行此命令后打印('成功转换xml到csv。')

 main()
  




我得到了baby_labels.csv文件,但打开此文件后,没有任何数据写入意味着为空。你可以帮帮我吗




0 个答案:

没有答案