How would I go around creating a MYSQL table schema inspecting an Excel(or CSV) file.
Are there any ready Python libraries for the task?
Column headers would be sanitized to column names. Datatype would be estimated based on the contents of the spreadsheet column. When done, data would be loaded to the table.
I have an Excel file of ~200 columns that I want to start normalizing.
Just for (my) reference, I documented below what I did:
LOAD DATA INFILECREATE TABLEwith all columns as TEXT, except for Primary keyLOAD DATA LOCAL INFILEloading all CSV data into TEXT fields.PROCEDURE ANALYSE, I was able toALTER TABLEto give columns the right types and lengths.PROCEDURE ANALYSEreturnsENUMfor any column with few distinct values, which is not what I needed, but I found that useful later for normalization. Eye-balling 200 columns was a breeze withPROCEDURE ANALYSE. Output from PhpMyAdmin propose table structure was junk.SELECT DISTINCTon columns andINSERTing results to separate tables. I have added to the old table a column for FK first. Just after theINSERT, I’ve got its ID andUPDATEed the FK column. When loop finished I’ve dropped old column leaving only FK column. Similarly with multiple dependent columns. It was much faster than I expected.python manage.py inspctdb, copied output to models.py and added all thoseForeignkeyFields as FKs do not exist on MyISAM. Wrote a little python views.py, urls.py, few templates…TADACreated https://blocl.uk/schools
based on data from https://www.get-information-schools.service.gov.uk/Downloads