Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python xml to csv

try:
    import xml.etree.cElementTree as ET
except ImportError:
    import xml.etree.ElementTree as ET
import pandas as pd

tree = ET.parse("file1.xml")
root = tree.getroot()
iter_root = root.iter()

l = {}
for elem in iter_root:
    l[str(elem.tag)] = str(elem.text)

df = pd.DataFrame.from_dict(l,orient="index")

df.to_csv('ABC.csv')
Comment

python code to convert csv to xml

with open('output.xml', 'w') as f: f.write('
'.join([convert_row(row) for row in data[1:]]))
Comment

PREVIOUS NEXT
Code Example
Python :: keys function in python 
Python :: check if a value is in index pandas dataframe 
Python :: python any() function 
Python :: comments in python 
Python :: string manipulation in python 
Python :: pandas get size of each group 
Python :: python import function from file 
Python :: converting time 
Python :: selenium wait until 
Python :: python remove the element in list 
Python :: pyspark on colab 
Python :: delete multiple dataframes at once in python 
Python :: convert ipynb to py 
Python :: Use operator in python list 
Python :: import csv in python 
Python :: login required 
Python :: Python NumPy split Function Syntax 
Python :: python language 
Python :: session of flask 
Python :: variable referenced before assignment python 
Python :: possible substrings of a string python 
Python :: python list to arguments 
Python :: dfs algorithm 
Python :: how to use str() 
Python :: how to connect mongodb database with python 
Python :: split dataframe row on delimiter python 
Python :: python double underscore methods 
Python :: what is thread in python 
Python :: Interfaces 
Python :: subtract constant from list 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =