Skip to content

Instantly share code, notes, and snippets.

@mattmc3
mattmc3 / import_xml_to_dataframe_to_sql.py
Created January 8, 2018 15:53
Python: Import XML to Pandas dataframe, and then dataframe to Sqlite database
import xml.etree.ElementTree as ET
import pandas as pd
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
# do this if running in jupyter
# pd.set_option('display.max_columns', None)
# convert XML to dataframe (assumes only one layer of nesting)
def xml2df(xml_data):