I need to add different types of files (CSV, XML, xlsx, etc.) to the database (Postgresql). I know how I can read it via pandas, but I have some issues with adding this to the database.
What libraries do I need to use? And does it need to convert them into one format?
CodePudding user response:
Read files with pandas:
csv_df = pd.read_csv('file.csv')
xml_df = pd.read_xml('file.xml')
xlsx_df = pd.read_excel('file.xlsx')
Add tables in db with columns like in your file
Add files to db
xlsx_df.to_sql('table_name', engine, if_exists='replace', index=False)