Advertisement
jarekmor

xml_parse_przyklad

Sep 19th, 2022
977
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.74 KB | None | 0 0
  1. import xml.etree.ElementTree as ET
  2. import pandas as pd
  3.  
  4. mytree = ET.parse('plik_xml.xml')
  5. myroot = mytree.getroot()
  6.  
  7. for i, item in enumerate(myroot):
  8.     print(i, item.tag)
  9.  
  10. len  = len(myroot[6].findall('run'))        
  11. all_runs_list = [ [] for x in range(len)]
  12.  
  13. for n in range(len):
  14.     for i in myroot[6].findall('run')[n]:
  15.         all_runs_list[n].append(i.attrib)
  16.  
  17. for k in range(len):
  18.     pd.DataFrame(all_runs_list[k]).to_csv('output{}.csv'.format(k), float_format='%.3f')      
  19.    
  20. df1 = pd.read_csv('output0.csv')
  21. df2 = pd.read_csv('output1.csv')
  22.  
  23. columns = ['number', 'depth', 'A', 'B', 'T', 'H', 'V', 'S']
  24.  
  25. df_1 = df1.copy()
  26. df_2 = df2.copy()
  27.  
  28. print(df_1[columns].reset_index())
  29. print(df_2[columns].reset_index())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement