READ XML DATA IN PANDAS
Listing 4.14 displays the contents of books.xml and Listing 4.15 displays the contents of pandas_read_xml.py that shows you how to read the contents of an XML document in Pandas.
LISTING 4.14: books.xml
<?xml version="1.0" encoding="UTF-8"?> <books> <book> <name>SQL Fundamentals</name> </book> <book> <name>SVG Fundamentals</name> </book> <book> <name>Python and Machine Learning</name> </book> </books>
LISTING 4.15: pandas_read_xml.py
# this code might require Python3.7
import pandas as pd
filename="books.xml"
df = pd.read_xml(filename)
print("XML data:")
print(df)
Listing 4.15 starts by initializing the variable with the name of an existing XML document and then invokes the Pandas read_xml() method in order to populate the variable df with data from the XML document, after which the contents of df are printed...