Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

convert xml to dataframe python

XML_file = 'file.xml' 
df = pd.DataFrame(XMl_file)
Comment

Read XML file to Pandas DataFrame

from lxml import objectify
xml = objectify.parse('Document1.xml')
root = xml.getroot()

data=[]
for i in range(len(root.getchildren())):
    data.append([child.text for child in root.getchildren()[i].getchildren()])

df = pd.DataFrame(data).T
df.columns = ['bathrooms', 'price', 'property_id']
Comment

Python: Extracting XML to DataFrame (Pandas)

path = 'AttributesXMLPandas.xml'
dfcols = ['ID', 'Text', 'CreationDate']

root = et.parse(path)
rows = root.findall('.//row')

# NESTED LIST
xml_data = [[row.get('Id'), row.get('Text'), row.get('CreationDate')] 
            for row in rows]

df_xml = pd.DataFrame(xml_data, columns=dfcols)

print(df_xml)

#   ID   Text             CreationDate
# 0  1  (...)  2011-08-30T21:15:28.063
# 1  2  (...)  2011-08-30T21:24:56.573
# 2  3  (...)                     None
Comment

PREVIOUS NEXT
Code Example
Python :: tensorflow.keras.utils.to_categorical 
Python :: python dict access 
Python :: how to count substring in a string in python 
Python :: pandas remove whitespace 
Python :: login url 
Python :: sort 2 lists together python 
Python :: file storage django 
Python :: python t test 
Python :: seaborn 
Python :: logistic regression algorithm 
Python :: __dict__ python? 
Python :: obtain items in directory and subdirectories 
Python :: if else in python 
Python :: check audio playing on windows python 
Python :: python os.remove permissionerror winerror 5 access is denied 
Python :: count number of objects django template 
Python :: python divide array into n parts 
Python :: python insert sorted 
Python :: pandas get highest values row 
Python :: tic-tac toe in pygame 
Python :: mysql store numpy array 
Python :: data type array 
Python :: Python-dotenv could not parse statement starting at line 1 
Python :: minmaxscaler transform 
Python :: how to set the size of a kivy window bigger than screen 
Python :: Sum of Product 1 
Python :: django cheat sheet pdf 
Python :: pygame keys keep pressing 
Python :: max value pandas 
Python :: django loginview 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =